multimediacommsengine/mmceshared/src/mcecomcodec.cpp
changeset 0 1bce908db942
child 18 91f50911ea81
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 #include "mcecomcodec.h"
       
    22 
       
    23 #include "mceserial.h"
       
    24 #include "mceevents.h"
       
    25 
       
    26 #ifdef MCE_COMMON_SERVER_SIDE
       
    27 
       
    28 #include <mmcccodecinformation.h>
       
    29 #include "mcesrvstream.h"
       
    30 
       
    31 #endif//MCE_COMMON_SERVER_SIDE
       
    32 
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CMceComCodec::CMceComCodec
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMceComCodec::CMceComCodec()
       
    42   : iID( TMceMediaId( (TUint32)&iID ) ),
       
    43     iPayloadType( 0 ),
       
    44     iIsEnabled( ETrue ),
       
    45     iBitrate( 0 ),
       
    46     iAllowedBitrates( 0 ),
       
    47     iCodecMode( 0 ),
       
    48     iFourCC( 0 ),
       
    49     iFrameSize( 0 ),
       
    50 	iState( CMceCodec::EEnabled ),
       
    51 	iPriority( 0 ),
       
    52 	iPriorityPreference( 0 ),
       
    53     iKeepAliveTimer( 0 ),
       
    54     iKeepAlivePayloadType( 0 ),
       
    55     iIsNegotiated( ETrue ),
       
    56     iCodecSdpIndex( 0 ),
       
    57     iPreference( 0 )
       
    58         {
       
    59         }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CMceComCodec::Id
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 TMceMediaId CMceComCodec::Id() const
       
    66     {
       
    67     return iID;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMceComCodec::Stream
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CMceComMediaStream* CMceComCodec::Stream() const
       
    75     {
       
    76     return iStream;
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CMceComCodec::ConstructL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CMceComCodec::ConstructL( CMceComCodec& aCodec )
       
    85     {
       
    86     iID = aCodec.iID;
       
    87     iSdpName = aCodec.iSdpName;
       
    88     iFmtpAttr = aCodec.iFmtpAttr ? aCodec.iFmtpAttr->AllocL() : NULL;
       
    89 	iPayloadType = aCodec.iPayloadType;
       
    90 	iFourCC = aCodec.iFourCC;
       
    91     iBitrate = aCodec.iBitrate;
       
    92 	iAllowedBitrates = aCodec.iAllowedBitrates;
       
    93 	iCodecMode = aCodec.iCodecMode;		
       
    94 	iFrameSize = aCodec.iFrameSize;
       
    95 	iState = aCodec.iState;
       
    96 	iPriority = aCodec.iPriority;
       
    97 	iPriorityPreference = aCodec.iPriorityPreference;
       
    98 	iKeepAliveTimer = aCodec.iKeepAliveTimer;
       
    99 	iKeepAlivePayloadType = aCodec.iKeepAlivePayloadType;
       
   100 	if ( aCodec.iKeepAliveData )
       
   101 	    {
       
   102 	    SetKeepAliveDataL( *aCodec.iKeepAliveData );
       
   103 	    }
       
   104     iIsNegotiated = aCodec.iIsNegotiated;
       
   105 	iCodecSdpIndex = aCodec.iCodecSdpIndex;
       
   106     }
       
   107 
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CMceComCodec::SerializationId
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 TUint64 CMceComCodec::SerializationId() const
       
   114     {
       
   115     return iID.Uint64();
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CMceComCodec::InternalizeFlatL
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CMceComCodec::InternalizeFlatL( RReadStream& aReadStream )
       
   123     {
       
   124     MceSerial::DecodeL( iSdpName, aReadStream );
       
   125     MceSerial::DecodeL( iID, aReadStream );
       
   126 	iPayloadType = aReadStream.ReadUint8L();
       
   127 	iFourCC = aReadStream.ReadUint32L();
       
   128 	iFrameSize = aReadStream.ReadUint32L();
       
   129 	iBitrate = aReadStream.ReadUint32L();
       
   130 	iAllowedBitrates = aReadStream.ReadUint32L();
       
   131 	iCodecMode = aReadStream.ReadUint32L();
       
   132 	iState = aReadStream.ReadInt32L();
       
   133 	iPriority = aReadStream.ReadInt32L();
       
   134 	iPriorityPreference = aReadStream.ReadInt32L();
       
   135     iKeepAliveTimer = aReadStream.ReadUint32L();
       
   136     iKeepAlivePayloadType = aReadStream.ReadUint32L();
       
   137     MceSerial::DecodeL( iKeepAliveData, aReadStream );
       
   138     }
       
   139     
       
   140 // -----------------------------------------------------------------------------
       
   141 // CMceComCodec::ExternalizeFlatL
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CMceComCodec::ExternalizeFlatL( RWriteStream& aWriteStream )
       
   145     {
       
   146     MceSerial::EncodeL( iSdpName, aWriteStream );
       
   147     MceSerial::EncodeL( iID, aWriteStream );
       
   148     aWriteStream.WriteUint8L( iPayloadType );
       
   149     aWriteStream.WriteUint32L( iFourCC );
       
   150     aWriteStream.WriteUint32L( iFrameSize );
       
   151     aWriteStream.WriteUint32L( iBitrate );
       
   152     aWriteStream.WriteUint32L( iAllowedBitrates );
       
   153     aWriteStream.WriteUint32L( iCodecMode );
       
   154     aWriteStream.WriteInt32L( iState );
       
   155     aWriteStream.WriteInt32L( iPriority );
       
   156     aWriteStream.WriteInt32L( iPriorityPreference );
       
   157     aWriteStream.WriteInt32L( iKeepAliveTimer );
       
   158     aWriteStream.WriteInt32L( iKeepAlivePayloadType );
       
   159     MceSerial::EncodeL( iKeepAliveData, aWriteStream );
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CMceComCodec::InternalizeL
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CMceComCodec::InternalizeL( MMceComSerializationContext& aSerCtx )
       
   167     {
       
   168     InternalizeFlatL( aSerCtx.ReadStream() );
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CMceComCodec::ExternalizeL
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CMceComCodec::ExternalizeL( MMceComSerializationContext& aSerCtx )
       
   176     {
       
   177     ExternalizeFlatL( aSerCtx.WriteStream() );
       
   178     }
       
   179 
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CMceComCodec::UpdateL
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CMceComCodec::UpdateL( CMceComCodec& aUpdate )
       
   186     {
       
   187     iSdpName = aUpdate.iSdpName;
       
   188     iID = aUpdate.iID;
       
   189     iPayloadType = aUpdate.iPayloadType;
       
   190     iFourCC = aUpdate.iFourCC;
       
   191     iBitrate = aUpdate.iBitrate;
       
   192     iAllowedBitrates = aUpdate.iAllowedBitrates;
       
   193     iCodecMode = aUpdate.iCodecMode;
       
   194 	iState = aUpdate.iState;
       
   195 	iPriority = aUpdate.iPriority;
       
   196 	iPriorityPreference = aUpdate.iPriorityPreference;
       
   197     iKeepAliveTimer = aUpdate.iKeepAliveTimer;
       
   198     iKeepAlivePayloadType = aUpdate.iKeepAlivePayloadType;
       
   199     if ( aUpdate.iKeepAliveData )
       
   200         {
       
   201         delete iKeepAliveData;
       
   202         iKeepAliveData = aUpdate.iKeepAliveData;
       
   203         aUpdate.iKeepAliveData = NULL;
       
   204         }
       
   205     else
       
   206         {
       
   207         SetKeepAliveDataL( KNullDesC8 );
       
   208         }
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CMceComCodec::ConstructL
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CMceComCodec::ConstructL( TMceComCodecName aSdpName )
       
   216     {
       
   217     iSdpName = aSdpName;
       
   218     SetKeepAliveDataL( KNullDesC8 );
       
   219     SetFmtpAttributeL( KNullDesC8 );
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CMceComCodec::Decodes
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 TBool CMceComCodec::Decodes( 
       
   227     const TDesC8& aRtpmapValue, 
       
   228     const TDesC8& /*aFmtpValue*/,
       
   229     TBool /*aIsStrictMatch*/ )
       
   230     {
       
   231     return aRtpmapValue.FindF( iSdpName ) == 0;
       
   232     }
       
   233     
       
   234 // -----------------------------------------------------------------------------
       
   235 // CMceComCodec::BaseFactory
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 TMceComFactory CMceComCodec::BaseFactory()
       
   239     {
       
   240     return TMceComFactory();
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CMceComCodec::FmtpAttr
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 TPtrC8 CMceComCodec::FmtpAttr() const
       
   248     {
       
   249     TPtrC8 existingFmtpVal( KNullDesC8() );
       
   250     if ( iFmtpAttr && iFmtpAttr->Length() > 0 )
       
   251         {
       
   252         existingFmtpVal.Set( *iFmtpAttr );
       
   253         }
       
   254     else if ( iFmtpProposal )
       
   255         {
       
   256         existingFmtpVal.Set( *iFmtpProposal );
       
   257         }
       
   258     else
       
   259         {
       
   260         // NOP
       
   261         }
       
   262     return existingFmtpVal;
       
   263     }
       
   264     
       
   265 // -----------------------------------------------------------------------------
       
   266 // CMceComCodec::SetFmtpAttributeL
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CMceComCodec::SetFmtpAttributeL( const TDesC8& aFmtpAttribute, TBool aReset )
       
   270     {
       
   271     if ( aReset || !iFmtpAttr )
       
   272         {
       
   273         HBufC8* fmtpAttr = aFmtpAttribute.AllocL();
       
   274         delete iFmtpAttr;
       
   275         iFmtpAttr = fmtpAttr;
       
   276         }
       
   277     else
       
   278         {
       
   279         iFmtpAttr = iFmtpAttr->ReAllocL( iFmtpAttr->Length() + 
       
   280                                          KMceFmtpSeparator().Length() +
       
   281                                          aFmtpAttribute.Length() );
       
   282         iFmtpAttr->Des().Append( KMceFmtpSeparator );
       
   283         iFmtpAttr->Des().Append( aFmtpAttribute );
       
   284         }
       
   285     }
       
   286 
       
   287     
       
   288 // -----------------------------------------------------------------------------
       
   289 // CMceComCodec::~CMceComCodec
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 CMceComCodec::~CMceComCodec()
       
   293     {
       
   294     delete iFmtpAttr;
       
   295     iFmtpAttr = NULL;
       
   296     delete iKeepAliveData;
       
   297     iKeepAliveData = NULL;
       
   298     delete iFmtpProposal;
       
   299     iFmtpProposal = NULL;
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CMceComCodec::EventReceivedL
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 TInt CMceComCodec::EventReceivedL( TMceEvent& aEvent )
       
   307     {
       
   308     TInt status = KMceEventNotOwner;
       
   309     TBool idMatch = aEvent.Id().iCodecID == iID;
       
   310     if ( !idMatch )
       
   311         {
       
   312         return KMceEventNotOwner;
       
   313         }
       
   314         
       
   315     if ( aEvent.Id().IsCodecId() )
       
   316         {
       
   317         status = KMceEventUpdate;
       
   318         }
       
   319     else
       
   320         {
       
   321         status = KMceEventNotConsumed;
       
   322         }
       
   323     
       
   324     return status;
       
   325     
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CMceComCodec::ResolveAllowedBitrates
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 TInt CMceComCodec::ResolveAllowedBitrates( 
       
   333     TUint /*aBitrate*/, TUint& /*aAllowedBitrates*/ )
       
   334     {
       
   335     return KErrNotSupported;
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CMceComCodec::SetEnabled
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 void CMceComCodec::SetEnabled( TBool aIsEnabled )
       
   343     {
       
   344     iIsEnabled = aIsEnabled;
       
   345     }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CMceComCodec::SendSupported
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 TBool CMceComCodec::SendSupported()
       
   352     {
       
   353     return ETrue;
       
   354     }
       
   355     
       
   356 // -----------------------------------------------------------------------------
       
   357 // CMceComCodec::IsEnabled
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 TBool CMceComCodec::IsEnabled() const
       
   361     {
       
   362     return iIsEnabled;
       
   363     }
       
   364         
       
   365 // -----------------------------------------------------------------------------
       
   366 // CMceComCodec::InitializeL
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CMceComCodec::InitializeL( CMceComMediaStream& aParent )
       
   370     {
       
   371     iStream = &aParent;
       
   372     }
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // CMceComCodec::SetKeepAliveDataL
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void CMceComCodec::SetKeepAliveDataL( const TDesC8& aKeepAliveData )
       
   379     { 
       
   380     HBufC8* keepaliveData = aKeepAliveData.AllocL();
       
   381     delete iKeepAliveData;
       
   382     iKeepAliveData = keepaliveData;
       
   383     }
       
   384 
       
   385     
       
   386 // -----------------------------------------------------------------------------
       
   387 // CMceComCodec::SetBitrate
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 TInt CMceComCodec::SetBitrate( TUint aBitrate )
       
   391     {
       
   392     if ( aBitrate )
       
   393         {
       
   394         iBitrate = aBitrate;
       
   395         return KErrNone;
       
   396         }
       
   397     else
       
   398         {
       
   399         return KErrArgument;
       
   400         }
       
   401     }
       
   402     
       
   403 // -----------------------------------------------------------------------------
       
   404 // CMceComCodec::SetAllowedBitrates
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 TInt CMceComCodec::SetAllowedBitrates( TUint aBitrates )
       
   408     {
       
   409     iAllowedBitrates = aBitrates;
       
   410     return KErrNone;
       
   411     }
       
   412 
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CMceComCodec::SetCodecMode
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 TInt CMceComCodec::SetCodecMode( TUint /*aCodecMode*/ )
       
   419     {
       
   420     return KErrNotSupported;
       
   421     }
       
   422 
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CMceComCodec::SetPayloadType
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 TInt CMceComCodec::SetPayloadType( TUint8 aPayloadType )
       
   429     {
       
   430     if ( aPayloadType <= KMaxDynPayloadType )
       
   431         {
       
   432         iPayloadType = aPayloadType;
       
   433         return KErrNone;
       
   434         }
       
   435     else
       
   436         {
       
   437         return KErrNotSupported;
       
   438         }
       
   439     }
       
   440 
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CMceComCodec::GetMaxBitRate
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 TUint CMceComCodec::GetMaxBitRate()
       
   447     {
       
   448     return iBitrate;
       
   449     }
       
   450 
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CMceComCodec::TIterator::TIterator
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 CMceComCodec::TIterator::TIterator( const RPointerArray<CMceComCodec>& aCodecs, 
       
   457                                     CMceComCodec::TIterator::TFilter aFilter,
       
   458                                     CMceComCodec* aCodec )
       
   459     : iFilter( aFilter ),
       
   460       iCodecs( aCodecs ),
       
   461       iCurrentIndex( 0 ),
       
   462       iCodec( aCodec )
       
   463     {
       
   464     }
       
   465             
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // CMceComCodec::TIterator::IsEof
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 TBool CMceComCodec::TIterator::IsEof()
       
   472     {
       
   473     return iCodecs.Count() == 0 || iCurrentIndex >= iCodecs.Count();
       
   474     }
       
   475             
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CMceComCodec::TIterator::Next
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 TBool CMceComCodec::TIterator::Next( 
       
   482     CMceComCodec*& aCandidate,  
       
   483     TIterator::TStreamStateMatchType aMatchType )
       
   484     {
       
   485     CMceComCodec* next = NULL;
       
   486     
       
   487     while( !next && !IsEof() )
       
   488         {
       
   489         CMceComCodec* codec = iCodecs[ iCurrentIndex ];
       
   490         TBool condition = EFalse;
       
   491         switch( iFilter )
       
   492             {
       
   493             case EFilterIsNegotiated:
       
   494                 {
       
   495                 condition = codec->iIsNegotiated;
       
   496                 break;
       
   497                 }
       
   498             case EFilterAssociatedLocal:
       
   499                 {
       
   500                 if ( iCodec && 
       
   501                      iCodec->Stream() &&
       
   502                      codec->Stream() &&
       
   503                      codec->Stream()->iStreamType == CMceComMediaStream::ELocalStream &&
       
   504                      ( ( aMatchType == EOtherSdpName && 
       
   505                          !codec->Decodes( iCodec->iSdpName, iCodec->FmtpAttr() ) ) || 
       
   506                        ( aMatchType == EExactMatch && 
       
   507                          codec->Decodes( iCodec->iSdpName, iCodec->FmtpAttr() ) ) ) )
       
   508                     {
       
   509                     CMceComMediaSource* source1 = iCodec->Stream()->Source();
       
   510                     CMceComMediaSource* source2 = codec->Stream()->Source();
       
   511                     
       
   512                     condition = ( source1 != NULL && source1 == source2 );
       
   513                     }
       
   514                 break;
       
   515                 }
       
   516             default:
       
   517                 {
       
   518                 condition = ETrue;
       
   519                 break;
       
   520                 }
       
   521             }
       
   522 
       
   523         next = condition ? codec : NULL;
       
   524                
       
   525         iCurrentIndex++;
       
   526         }
       
   527 
       
   528     aCandidate = next;
       
   529     return aCandidate ? ETrue : EFalse;
       
   530     
       
   531     }
       
   532     
       
   533     
       
   534 // -----------------------------------------------------------------------------
       
   535 // CMceComCodec::TIterator::Reset
       
   536 // -----------------------------------------------------------------------------
       
   537 //
       
   538 void CMceComCodec::TIterator::Reset()
       
   539     {
       
   540     iCurrentIndex = 0;
       
   541     }
       
   542             
       
   543 // -----------------------------------------------------------------------------
       
   544 // CMceComCodec::TIterator::SetFilter
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 void CMceComCodec::TIterator::SetFilter( 
       
   548     CMceComCodec::TIterator::TFilter aFilter,
       
   549     CMceComCodec* aCodec )
       
   550     {
       
   551     iFilter = aFilter;
       
   552     iCodec = aCodec;
       
   553     }
       
   554             
       
   555 // -----------------------------------------------------------------------------
       
   556 // CMceComCodec::TIterator::Count
       
   557 // -----------------------------------------------------------------------------
       
   558 //
       
   559 TInt CMceComCodec::TIterator::Count()
       
   560     {
       
   561     TInt count = iCodecs.Count();
       
   562     if ( iFilter )
       
   563         {
       
   564         TInt currentIndex = iCurrentIndex;
       
   565         Reset();
       
   566         CMceComCodec* codec = NULL;
       
   567         count = 0;
       
   568         while( Next( codec ) )
       
   569             {
       
   570             count++;
       
   571             }
       
   572         iCurrentIndex = currentIndex;
       
   573         }
       
   574 
       
   575     return count;
       
   576     }
       
   577     
       
   578     
       
   579 #ifdef MCE_COMMON_SERVER_SIDE
       
   580 
       
   581 // -----------------------------------------------------------------------------
       
   582 // CMceComCodec::SynchronizeL
       
   583 // -----------------------------------------------------------------------------
       
   584 //
       
   585 void CMceComCodec::SynchronizeL( CMceComCodec& aCodec, TBool aRoleAnswerer )
       
   586     {
       
   587     if ( aRoleAnswerer )
       
   588         {
       
   589         SetFmtpFromIncomingSdpL( *aCodec.iFmtpAttr, aRoleAnswerer );
       
   590     	iPayloadType = aCodec.iPayloadType;
       
   591         }
       
   592     iCodecSdpIndex = aCodec.iCodecSdpIndex;
       
   593 	iIsNegotiated = aCodec.iIsNegotiated;
       
   594     }
       
   595     
       
   596     
       
   597 // -----------------------------------------------------------------------------
       
   598 // CMceComCodec::MccPopulateL
       
   599 // -----------------------------------------------------------------------------
       
   600 //
       
   601 void CMceComCodec::MccPopulateL( CMccCodecInformation& aMccCodec,
       
   602                                  CMceSrvStream& aStream,
       
   603                                  TMceNegotiationRole aRole )
       
   604     {
       
   605     MccEncodeL( aMccCodec, aStream );
       
   606     if ( aRole == EMceRoleOfferer )
       
   607         {
       
   608         // Create fmtp
       
   609         aMccCodec.CreateFmtpAttrListL();
       
   610         }
       
   611 
       
   612     UpdateL( aMccCodec );
       
   613 	
       
   614     }
       
   615 
       
   616 
       
   617 // -----------------------------------------------------------------------------
       
   618 // CMceComCodec::UpdateL
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 void CMceComCodec::UpdateL( CMccCodecInformation& aMccCodec )
       
   622     {
       
   623 	SetFmtpAttributeL( aMccCodec.GetFmtpL() );
       
   624 	iSdpName = aMccCodec.SdpName();
       
   625     }
       
   626 
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CMceComCodec::MccEncodeL
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 void CMceComCodec::MccEncodeL( CMccCodecInformation& aMccCodec, 
       
   633                                CMceSrvStream& aStream )
       
   634     {	    
       
   635     // Encode common 
       
   636     EncodeCodecCommonL( aMccCodec );
       
   637 	       
       
   638     // Encode codec specific stuff
       
   639     DoMccEncodeL( aMccCodec, aStream );
       
   640     }
       
   641 
       
   642 // -----------------------------------------------------------------------------
       
   643 // CMceComCodec::MccDecodeL
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 void CMceComCodec::MccDecodeL( CMccCodecInformation& aMccCodec )
       
   647     {
       
   648     TBool fmtpReady = iFmtpAttr && iFmtpAttr->Length();
       
   649     if ( fmtpReady )
       
   650         {
       
   651         // Parse fmtp attribute
       
   652         aMccCodec.SetFmtpAttrL( *iFmtpAttr );
       
   653         }
       
   654         
       
   655     // Copy common values from mcc codec
       
   656     DecodeCodecCommonL( aMccCodec );
       
   657     
       
   658     // Copy codec specific values from mcc codec
       
   659     DoMccDecodeL( aMccCodec );
       
   660     
       
   661     if ( !fmtpReady )
       
   662         {
       
   663         aMccCodec.CreateFmtpAttrListL();
       
   664         }
       
   665         
       
   666 	SetFmtpAttributeL( aMccCodec.GetFmtpL() );
       
   667     }
       
   668     
       
   669 // -----------------------------------------------------------------------------
       
   670 // CMceComCodec::MccValidateL
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 CMceComCodec* CMceComCodec::MccValidateL( CMccCodecInformation& aMccCodec,
       
   674                                           CMceSrvStream& aStream,
       
   675                                           TMceNegotiationRole aRole )
       
   676     {
       
   677     CMceComCodec* bidirectional = NULL;
       
   678     
       
   679     aMccCodec.SetFmtpAttrL( *iFmtpAttr );
       
   680     
       
   681     // Validation not needed for disabled streams
       
   682     if ( aStream.Data().IsEnabled() )
       
   683         {
       
   684         // Do common validation
       
   685        	if( (TInt)aMccCodec.Bitrate() < 0 )
       
   686     		{
       
   687     		// Bitrate in the answer was out of range or 
       
   688     		User::Leave( KErrNotSupported );
       
   689     		}
       
   690     		
       
   691         // Do codec specific validation
       
   692         bidirectional = DoMccValidateL( aMccCodec, aStream, aRole );
       
   693         }
       
   694 
       
   695     //Validation ok => when answerer update mcc codec with codec values
       
   696     //                 when offerer update codec with mcc codec values
       
   697     if ( aRole == EMceRoleAnswerer )
       
   698         {
       
   699         // Encode
       
   700         MccEncodeL( aMccCodec, aStream );
       
   701     
       
   702         //update fmtp
       
   703         UpdateL( aMccCodec );
       
   704     	
       
   705         }
       
   706     else
       
   707         {
       
   708         // Copy common values from mcc codec
       
   709         DecodeCodecCommonL( aMccCodec );
       
   710         
       
   711         // Copy codec specific values from mcc codec
       
   712         DoMccDecodeL( aMccCodec );
       
   713         }
       
   714      
       
   715     return bidirectional;  
       
   716     }
       
   717 
       
   718 // -----------------------------------------------------------------------------
       
   719 // CMceComCodec::MccAdjustL
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 void CMceComCodec::MccAdjustL( CMccCodecInformation& aMccCodec,
       
   723                                CMceSrvStream& aStream )
       
   724     {
       
   725     User::LeaveIfError( aMccCodec.SetPayloadType( iPayloadType ) );
       
   726 	    
       
   727     DoMccAdjustL( aMccCodec, aStream );
       
   728     
       
   729     }
       
   730 
       
   731 
       
   732 // -----------------------------------------------------------------------------
       
   733 // CMceComCodec::MccRequireSignalling
       
   734 // -----------------------------------------------------------------------------
       
   735 //
       
   736 TInt CMceComCodec::MccRequireSignalling( 
       
   737     const CMceSrvStream& aStream,
       
   738     const CMccCodecInformation& aMccCurentCodec, 
       
   739     const CMccCodecInformation& aMccUpdateCodec ) const
       
   740     {
       
   741     TInt action = KMceRequiresSignalling;
       
   742 
       
   743     if ( !aMccCurentCodec.RequireSignalling( aMccUpdateCodec ) )
       
   744         {
       
   745         action = DoMccRequireSignalling( aStream, aMccCurentCodec, aMccUpdateCodec );
       
   746         }
       
   747         
       
   748     return action;                
       
   749     }
       
   750 
       
   751     
       
   752 // -----------------------------------------------------------------------------
       
   753 // CMceComCodec::SetState
       
   754 // -----------------------------------------------------------------------------
       
   755 //
       
   756 void CMceComCodec::SetState( TMceMccComEvent& aEvent )
       
   757     {
       
   758 
       
   759     iIsEnabled = aEvent.iEvent == KMccStreamPrepared ?
       
   760                     ETrue :
       
   761                  aEvent.iEvent == KMccStreamStarted ?
       
   762                     ETrue :
       
   763                  aEvent.iEvent == KMccStreamStopped ?
       
   764                     EFalse :
       
   765                  aEvent.iEvent == KMccStreamPaused ?
       
   766                     EFalse :
       
   767                  aEvent.iEvent == KMccStreamResumed ?
       
   768                    ETrue : iIsEnabled;
       
   769     
       
   770     }
       
   771 
       
   772 // -----------------------------------------------------------------------------
       
   773 // CMceComCodec::Merge
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 void CMceComCodec::Merge( CMceComCodec& aMergeWith )
       
   777     {
       
   778     CMceComMediaStream* stream = Stream();
       
   779     if ( IS_RECEIVESTREAM( stream ) )
       
   780         {
       
   781         iIsEnabled = aMergeWith.iIsEnabled;
       
   782         }
       
   783     iIsNegotiated = aMergeWith.iIsNegotiated;
       
   784     iCodecSdpIndex = aMergeWith.iCodecSdpIndex;
       
   785     }
       
   786 
       
   787 // -----------------------------------------------------------------------------
       
   788 // CMceComCodec::SetFmtpProposalL
       
   789 // -----------------------------------------------------------------------------
       
   790 //
       
   791 TBool CMceComCodec::SetFmtpProposalL( const TDesC8& aFmtpProposal )
       
   792     {
       
   793     HBufC8* proposal = aFmtpProposal.AllocL();
       
   794     delete iFmtpProposal;
       
   795     iFmtpProposal = proposal;
       
   796     return ETrue;
       
   797     }
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 // CMceComCodec::SetFmtpFromIncomingSdpL
       
   801 // -----------------------------------------------------------------------------
       
   802 //
       
   803 void CMceComCodec::SetFmtpFromIncomingSdpL( 
       
   804     const TDesC8& aFmtpAttribute, 
       
   805     TBool /*aRoleAnswerer*/,
       
   806     TBool aReset )
       
   807     {
       
   808     SetFmtpAttributeL( aFmtpAttribute, aReset );
       
   809     }
       
   810 
       
   811 // -----------------------------------------------------------------------------
       
   812 // CMceComCodec::FtmpForOutgoingSdpLC
       
   813 // -----------------------------------------------------------------------------
       
   814 //    
       
   815 HBufC8* CMceComCodec::FtmpForOutgoingSdpLC()
       
   816     {
       
   817     HBufC8* fmtp = NULL;
       
   818     if ( iFmtpAttr )
       
   819         {
       
   820         fmtp = iFmtpAttr->AllocLC();
       
   821         }
       
   822     else
       
   823         {
       
   824         fmtp = KNullDesC8().AllocLC();
       
   825         }
       
   826     return fmtp;
       
   827     }
       
   828         
       
   829 // -----------------------------------------------------------------------------
       
   830 // CMceComCodec::EncodeCodecCommonL
       
   831 // -----------------------------------------------------------------------------
       
   832 //
       
   833 void CMceComCodec::EncodeCodecCommonL( CMccCodecInformation& aMccCodec )
       
   834     {
       
   835     User::LeaveIfError( aMccCodec.SetPayloadType( iPayloadType ) );
       
   836 	User::LeaveIfError( aMccCodec.SetAllowedBitrates( iAllowedBitrates ) );
       
   837 	User::LeaveIfError( aMccCodec.SetCodecMode( (TCodecMode)iCodecMode ) );
       
   838 	User::LeaveIfError( aMccCodec.SetBitrate( iBitrate ) );
       
   839 	aMccCodec.SetPriority( iPriority );
       
   840 	aMccCodec.SetPriorityPreference( iPriorityPreference );
       
   841 	User::LeaveIfError( aMccCodec.SetKeepAliveTimer( iKeepAliveTimer ) );
       
   842 	User::LeaveIfError( aMccCodec.SetKeepAlivePT( iKeepAlivePayloadType ) );
       
   843 	if ( iKeepAliveData && iKeepAliveData->Length() > 0 )
       
   844 	    {
       
   845 	    User::LeaveIfError( aMccCodec.SetKeepAliveData( *iKeepAliveData ) );
       
   846 	    }	
       
   847 	}
       
   848 
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // CMceComCodec::DecodeCodecCommonL
       
   852 // -----------------------------------------------------------------------------
       
   853 //
       
   854 void CMceComCodec::DecodeCodecCommonL( CMccCodecInformation& aMccCodec )
       
   855     {  
       
   856 	iAllowedBitrates = aMccCodec.AllowedBitrates();
       
   857 	iCodecMode = (TUint32)aMccCodec.CodecMode();
       
   858 	iFourCC = aMccCodec.FourCC();
       
   859 	iFrameSize = aMccCodec.FrameSize();
       
   860 	iBitrate =  aMccCodec.Bitrate();
       
   861 	iPriority = aMccCodec.Priority();
       
   862 	iPriorityPreference = aMccCodec.PriorityPreference();
       
   863 	iKeepAliveTimer = aMccCodec.KeepAliveTimer();
       
   864 	iKeepAlivePayloadType = aMccCodec.KeepAlivePT();
       
   865 	SetKeepAliveDataL( aMccCodec.KeepAliveData() );
       
   866     }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // CMceComCodec::SetDefaultFmtpAttributeL
       
   870 // -----------------------------------------------------------------------------
       
   871 //
       
   872 void CMceComCodec::SetDefaultFmtpAttributeL()
       
   873     {
       
   874     DoSetDefaultFmtpAttributeL();
       
   875     }
       
   876 
       
   877 // -----------------------------------------------------------------------------
       
   878 // CMceComCodec::DoMccValidateL
       
   879 // -----------------------------------------------------------------------------
       
   880 CMceComCodec* CMceComCodec::DoMccValidateL( CMccCodecInformation& aMccCodec,
       
   881 		                                    CMceSrvStream& /*aStream*/, 
       
   882 		                                    TMceNegotiationRole /*aRole*/ )
       
   883 	{
       
   884 	if ( aMccCodec.CodecMode() != (TCodecMode)iCodecMode )
       
   885 		{
       
   886 		// codec-mode was different, fail.
       
   887 		User::Leave(KErrNotSupported);
       
   888 		}
       
   889 	return NULL;
       
   890 	}
       
   891        
       
   892 #endif//MCE_COMMON_SERVER_SIDE
       
   893     
       
   894