sipvoipprovider/src/svputility.cpp
branchRCL_3
changeset 21 f742655b05bf
parent 20 65a3ef1d5bd0
child 22 d38647835c2e
equal deleted inserted replaced
20:65a3ef1d5bd0 21:f742655b05bf
     1 /*
       
     2 * Copyright (c) 2006-2010 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:  Provides static utility functions for SVP
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // #include <WlanInternalPSKeys.h>
       
    20 #include <sysutil.h>
       
    21 #include <sipprofile.h>
       
    22  
       
    23 #include <CommonEngineDomainCRKeys.h> // for accept-language -header
       
    24 #include <centralrepository.h> // for language code
       
    25 #include <settingsinternalcrkeys.h> // Settings UIs CR keys
       
    26 #include <unsafprotocolscrkeys.h>  // Keys for keep-alive value,ipappsrv_dom\nat_settings_api
       
    27 
       
    28 #include <mceaudiocodec.h>
       
    29 #include <mceamrcodec.h>
       
    30 #include <mceg711codec.h>
       
    31 #include <mceilbccodec.h>
       
    32 #include <mcecodec.h>
       
    33 #include <mcedtmfcodec.h>
       
    34 #include <mceamrwbcodec.h>
       
    35 #include <mcertpsource.h>
       
    36 #include <mcemicsource.h>
       
    37 #include <mcertpsink.h>
       
    38 #include <pathinfo.h>
       
    39 #include <crcseprofileentry.h>
       
    40 #include <crcseprofileregistry.h>
       
    41 #include <crcseaudiocodecregistry.h>
       
    42 #include <crcseaudiocodecentry.h>
       
    43 
       
    44 #include "voipeventlog.h"                   // CVoipEventLog
       
    45 #include "voiperrorentry.h"                 // CVoipErrorEntry
       
    46 #include "cipapputilsaddressresolver.h"     // CIPAppUtilsAddressResolver
       
    47 
       
    48 #include "svputility.h"
       
    49 #include "svplogger.h"
       
    50 #include "svpsipconsts.h"
       
    51 #include "svplanguagetagconsts.h"
       
    52 #include "svpaudioutility.h"
       
    53 
       
    54 // LOCAL CONSTANTS
       
    55 // Default audio frame size in milliseconds for calculating jitterbuffer size
       
    56 const TInt32 KJitterBufferFrameSize = 20;
       
    57 
       
    58 // Constants for iLBC 20 and 30ms modes
       
    59 const TUint32 KSvpilbcMode20ms = 20;
       
    60 const TUint32 KSvpilbcMode30ms = 30;
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CSVPUtility::NewL
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CSVPUtility* CSVPUtility::NewL()
       
    68     {
       
    69     CSVPUtility* self = new( ELeave ) CSVPUtility();
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CSVPUtility::ConstructL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CSVPUtility::ConstructL()
       
    82     {
       
    83     SVPDEBUG1("CSVPUtility::ConstructL()");                                                                            
       
    84     iPreferredCodec = 0;
       
    85     iRoundIndex = 0;
       
    86     
       
    87     // create CVoipEventLog
       
    88     TRAP_IGNORE( iVoipEventLogger = CVoipEventLog::NewL() );
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CSVPUtility::CSVPUtility
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 CSVPUtility::CSVPUtility()
       
    96     {
       
    97     SVPDEBUG1("CSVPUtility::CSVPUtility()");
       
    98     }
       
    99 
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CSVPUtility::~CSVPUtility
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CSVPUtility::~CSVPUtility()
       
   106     {
       
   107     SVPDEBUG1("CSVPUtility::~CSVPUtility()");
       
   108     delete iVoipEventLogger;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CSVPUtility::SetAudioCodecsMOL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CSVPUtility::SetAudioCodecsMOL( TUint32 aVoIPProfileId, 
       
   116                                      CMceAudioStream& aAudioInStream,
       
   117                                      TInt aKeepAliveValue )
       
   118     {
       
   119     SVPDEBUG1("CSVPUtility::SetAudioCodecsMOL: IN");
       
   120     
       
   121     RArray< TUint32 > codecIds;
       
   122     CleanupClosePushL( codecIds );
       
   123      
       
   124     // clear codec priority preferrence variable
       
   125     iPreferredCodec = 0;
       
   126 
       
   127     CRCSEProfileEntry* profile = CRCSEProfileEntry::NewLC();
       
   128     CRCSEAudioCodecEntry* codecprofile = CRCSEAudioCodecEntry::NewLC();
       
   129     CRCSEProfileRegistry* rCSEProfile = CRCSEProfileRegistry::NewLC();
       
   130     CRCSEAudioCodecRegistry* rCSEAudioCodec = 
       
   131                                      CRCSEAudioCodecRegistry::NewLC();
       
   132     
       
   133     // Get VoIP profile from RCSE
       
   134     rCSEProfile->FindL( aVoIPProfileId, *profile );
       
   135     
       
   136     // fetch codec id's
       
   137     GetCodecIdsByVoIPProfileIdL( *profile, codecIds );
       
   138     TBool capabilitiesSet = EFalse;
       
   139         
       
   140     // Set capabilities
       
   141     for( TInt j = 0; j < codecIds.Count(); j++ )
       
   142         {
       
   143         rCSEAudioCodec->FindL( codecIds[ j ], *codecprofile );
       
   144         if ( !codecprofile->iMediaSubTypeName.CompareF( KAudioCodecCN ) )
       
   145             {
       
   146             iCN = ETrue;
       
   147             }
       
   148         else
       
   149             {
       
   150             SVPDEBUG2("CSVPUtility::SetAudioCodecsMOL: j: %d", j);
       
   151             MoCallCapabilitiesL( aAudioInStream, 
       
   152                                  *profile, 
       
   153                                  *codecprofile );
       
   154             capabilitiesSet = ETrue;
       
   155             }
       
   156         }
       
   157      
       
   158     // in Mo case, redundancy is never offered
       
   159     iRed = EFalse;
       
   160     
       
   161     if ( capabilitiesSet )
       
   162         {
       
   163         SetDtmfL( *profile, aAudioInStream );
       
   164         }
       
   165     
       
   166     SetMediaQoSL( profile->iMediaQOS, aAudioInStream.Session() );
       
   167     
       
   168     // set comfort noise for PCMA/PCMU & ILBC if CN provisioned
       
   169     // also handles keep alive logics
       
   170     if ( iCN )
       
   171         {
       
   172         SetComfortNoiseL( aAudioInStream );
       
   173         RemoveUnnecessaryCodecsL( aAudioInStream );
       
   174         SetCNKeepAliveL( aAudioInStream, aKeepAliveValue ); 
       
   175         }
       
   176     else
       
   177         {
       
   178         RemoveUnnecessaryCodecsL( aAudioInStream );
       
   179         SetKeepAliveL( aAudioInStream, aKeepAliveValue ); 
       
   180         }
       
   181    
       
   182     // Check RTCP for actual and bound stream as we do not have knowledge where
       
   183     // the actual RTP sink is residing
       
   184     CheckRtcpSettingL( profile->iRTCP, aAudioInStream );
       
   185     if ( aAudioInStream.BoundStream() )
       
   186         {
       
   187         CheckRtcpSettingL( profile->iRTCP, aAudioInStream.BoundStreamL() );
       
   188         }
       
   189     
       
   190     // RCSE objects can be deleted
       
   191     CleanupStack::PopAndDestroy( 5, &codecIds );
       
   192 
       
   193     // Leave if codec information was not found.
       
   194     if ( !aAudioInStream.Codecs().Count() )
       
   195         {
       
   196         SVPDEBUG1("CSVPUtility::SetAudioCodecsMOL KErrNotFound");
       
   197         User::Leave( KErrNotFound );
       
   198         }
       
   199     
       
   200     SVPDEBUG1("CSVPUtility::SetAudioCodecsMOL: OUT");
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CSVPUtility::SetKeepAliveL
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CSVPUtility::SetKeepAliveL( CMceAudioStream& aAudioStream,
       
   208                                  TInt aKeepAliveValue )
       
   209     {
       
   210     SVPDEBUG1( "CSVPUtility::SetKeepAliveL In ")
       
   211     
       
   212     TInt count = aAudioStream.Codecs().Count();
       
   213     SVPDEBUG2( "CSVPUtility::SetKeepAliveL Codec count: %d ", count )
       
   214     
       
   215     // values should be set to bound stream also
       
   216     CMceAudioStream& boundStream = 
       
   217         static_cast< CMceAudioStream& > ( aAudioStream.BoundStreamL() );
       
   218     
       
   219     __ASSERT_ALWAYS( &boundStream, User::Leave( KSVPErrCodecMismatch ) );
       
   220     // Amount of codecs should be the same in audio- and boundstreams
       
   221     __ASSERT_ALWAYS( count == boundStream.Codecs().Count(),
       
   222                      User::Leave( KSVPErrCodecMismatch ) );
       
   223     
       
   224     TInt maxPl( 0 );
       
   225     TInt minPl( 0 );
       
   226     // first check the max payload in the codec set
       
   227     while ( count-- )
       
   228         {
       
   229         minPl = aAudioStream.Codecs()[ count ]->PayloadType();
       
   230         if ( minPl > maxPl )
       
   231             {
       
   232             maxPl = minPl;
       
   233             }  
       
   234         }
       
   235     
       
   236     count = aAudioStream.Codecs().Count();
       
   237     // if max pl less than def 120, set 120 as pl
       
   238     if ( KSVPDefKeepAlivePl > maxPl )
       
   239         {
       
   240         while( count-- )
       
   241             {
       
   242             SVPDEBUG1( "CSVPUtility::SetKeepAliveL A ")
       
   243             aAudioStream.Codecs()[ count ]->SetKeepAlivePayloadTypeL( KSVPDefKeepAlivePl );
       
   244             aAudioStream.Codecs()[ count ]->SetKeepAliveDataL( KNullDesC8 );
       
   245             aAudioStream.Codecs()[ count ]->SetKeepAliveTimerL( aKeepAliveValue );
       
   246             boundStream.Codecs()[ count ]->SetKeepAlivePayloadTypeL( KSVPDefKeepAlivePl );
       
   247             boundStream.Codecs()[ count ]->SetKeepAliveDataL( KNullDesC8 );
       
   248             boundStream.Codecs()[ count ]->SetKeepAliveTimerL( aKeepAliveValue );
       
   249             }
       
   250         }
       
   251     else if ( KSVPDefKeepAlivePlMax > maxPl )
       
   252         {
       
   253         while( count-- )
       
   254             {
       
   255             SVPDEBUG1( "CSVPUtility::SetKeepAliveL B ")
       
   256             aAudioStream.Codecs()[ count ]->SetKeepAlivePayloadTypeL( maxPl + 1 );
       
   257             aAudioStream.Codecs()[ count ]->SetKeepAliveDataL( KNullDesC8 );
       
   258             aAudioStream.Codecs()[ count ]->SetKeepAliveTimerL( aKeepAliveValue );
       
   259             boundStream.Codecs()[ count ]->SetKeepAlivePayloadTypeL( maxPl + 1 );
       
   260             boundStream.Codecs()[ count ]->SetKeepAliveDataL( KNullDesC8 );
       
   261             boundStream.Codecs()[ count ]->SetKeepAliveTimerL( aKeepAliveValue );
       
   262             }
       
   263         }
       
   264     
       
   265     SVPDEBUG1( "CSVPUtility::SetKeepAliveL Out ")
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // CSVPUtility::SetCNKeepAliveL
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CSVPUtility::SetCNKeepAliveL( CMceAudioStream& aAudioStream,
       
   273                                    TInt aKeepAliveValue )
       
   274     {
       
   275     SVPDEBUG1( "CSVPUtility::SetCNKeepAliveL In ")
       
   276     
       
   277     TInt count = aAudioStream.Codecs().Count();
       
   278     SVPDEBUG2( "CSVPUtility::SetCNKeepAliveL Codec count: %d ", count )
       
   279     
       
   280     TInt mostPreferred = 0; 
       
   281     // bound stream should be present always
       
   282     CMceAudioStream& boundStream = 
       
   283         static_cast< CMceAudioStream& > ( aAudioStream.BoundStreamL() );
       
   284     
       
   285     __ASSERT_ALWAYS( &boundStream, User::Leave( KSVPErrCodecMismatch ) );
       
   286     // Amount of codecs should be the same in audio- and boundstreams
       
   287     __ASSERT_ALWAYS( count == boundStream.Codecs().Count(),
       
   288                      User::Leave( KSVPErrCodecMismatch ) );
       
   289     
       
   290     // find most preferred codec and set keepalive timer
       
   291     // value and payload for most preferred codec
       
   292     while( count-- )
       
   293         {
       
   294         const TDesC8& codec = aAudioStream.Codecs()[ count ]->SdpName();
       
   295          
       
   296         // handle only real audio codecs
       
   297         if (  KErrNotFound == codec.Find( KCN ) && KErrNotFound == codec.Find( KTELEVENT )  )
       
   298             {
       
   299             if ( 0 == aAudioStream.Codecs()[ count ]->Preference() )
       
   300                 {
       
   301                 SVPDEBUG2( "Most preferred codec: %d ", count )
       
   302                 SVPDEBUG2( "Payload: %d ", aAudioStream.Codecs()[ count ]->PayloadType() )
       
   303                 aAudioStream.Codecs()[ count ]->SetKeepAliveTimerL( aKeepAliveValue );
       
   304                 aAudioStream.Codecs()[ count ]->SetKeepAlivePayloadTypeL( KSVPCNPayloadType );
       
   305                 aAudioStream.Codecs()[ count ]->SetKeepAliveDataL( KNullDesC8 );
       
   306                 boundStream.Codecs()[ count ]->SetKeepAliveTimerL( aKeepAliveValue );
       
   307                 boundStream.Codecs()[ count ]->SetKeepAlivePayloadTypeL( KSVPCNPayloadType );
       
   308                 boundStream.Codecs()[ count ]->SetKeepAliveDataL( KNullDesC8 );
       
   309                 mostPreferred = count;
       
   310                 }
       
   311            }
       
   312         }
       
   313     
       
   314     count = aAudioStream.Codecs().Count();
       
   315     while ( count-- )
       
   316         {
       
   317         if ( mostPreferred != count )
       
   318             {
       
   319             SVPDEBUG2( "Timer value 0 for codec: %d ", count )
       
   320             aAudioStream.Codecs()[ count ]->SetKeepAliveTimerL( 0 );
       
   321             aAudioStream.Codecs()[ count ]->SetKeepAlivePayloadTypeL( KSVPCNPayloadType );
       
   322             aAudioStream.Codecs()[ count ]->SetKeepAliveDataL( KNullDesC8 );
       
   323             boundStream.Codecs()[ count ]->SetKeepAliveTimerL( 0 );
       
   324             boundStream.Codecs()[ count ]->SetKeepAlivePayloadTypeL( KSVPCNPayloadType );
       
   325             boundStream.Codecs()[ count ]->SetKeepAliveDataL( KNullDesC8 );
       
   326             }
       
   327         }
       
   328     
       
   329     SVPDEBUG1( "CSVPUtility::SetCNKeepAliveL Out ")
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // CSVPUtility::IsComfortNoise
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 TBool CSVPUtility::IsComfortNoise( CMceAudioStream& aStream )
       
   337     {
       
   338     SVPDEBUG1( "CSVPUtility::IsComfortNoise In ")
       
   339     TInt count = aStream.Codecs().Count();
       
   340     while ( count-- )
       
   341         {
       
   342         if ( !aStream.Codecs()[ count ]->SdpName().CompareF( KCN ) )
       
   343             {
       
   344             return ETrue;
       
   345             }
       
   346         }
       
   347     return EFalse;
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // CSVPUtility::SetAudioCodecsForEmergencyL
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 void CSVPUtility::SetAudioCodecsForEmergencyL( 
       
   355     CMceAudioStream& aAudioInStream,
       
   356     TInt aKeepAliveValue, 
       
   357     TInt32 aVoipProfileId )
       
   358     {
       
   359     SVPDEBUG1("CSVPUtility::SetAudioCodecsForEmergencyL() In")
       
   360         
       
   361     // clear codec priority preferrence variable
       
   362     iPreferredCodec = 0;
       
   363 
       
   364     // Default profile
       
   365     CRCSEProfileEntry* profile = CRCSEProfileEntry::NewLC(); // CS:1
       
   366     
       
   367     // Set codecs
       
   368     if ( KErrNotFound == aVoipProfileId )
       
   369         {
       
   370         // No VoIP profile, use default profile values
       
   371         SVPDEBUG1("CSVPUtility::SetAudioCodecsForEmergencyL, no VoIP profile")
       
   372 
       
   373         // Create default codecs (PCMA, PCMU, AMR, iLBC, G729) and set 
       
   374         // capabilities
       
   375         CRCSEAudioCodecEntry* codec = CRCSEAudioCodecEntry::NewLC(); // CS:2
       
   376         codec->SetDefaultCodecValueSet( KAudioCodecPCMA() );
       
   377         MoCallCapabilitiesL( aAudioInStream, *profile, *codec );
       
   378         CleanupStack::PopAndDestroy( codec ); // CS:1
       
   379 
       
   380         codec = CRCSEAudioCodecEntry::NewLC(); // CS:2
       
   381         codec->SetDefaultCodecValueSet( KAudioCodecPCMU() );
       
   382         MoCallCapabilitiesL( aAudioInStream, *profile, *codec );
       
   383         CleanupStack::PopAndDestroy( codec ); // CS:1
       
   384 
       
   385         codec = CRCSEAudioCodecEntry::NewLC(); // CS:2
       
   386         codec->SetDefaultCodecValueSet( KAudioCodecAMR() );
       
   387         MoCallCapabilitiesL( aAudioInStream, *profile, *codec );
       
   388         CleanupStack::PopAndDestroy( codec ); // CS:1
       
   389 
       
   390         codec = CRCSEAudioCodecEntry::NewLC(); // CS:2
       
   391         codec->SetDefaultCodecValueSet( KAudioCodeciLBC() );
       
   392         MoCallCapabilitiesL( aAudioInStream, *profile, *codec );
       
   393         CleanupStack::PopAndDestroy( codec ); // CS:1
       
   394 
       
   395         codec = CRCSEAudioCodecEntry::NewLC(); // CS:2
       
   396         codec->SetDefaultCodecValueSet( KAudioCodecG729() );
       
   397         MoCallCapabilitiesL( aAudioInStream, *profile, *codec );
       
   398         CleanupStack::PopAndDestroy( codec ); // CS:1
       
   399         }
       
   400     else
       
   401         {
       
   402         // VoIP profile exists
       
   403         SVPDEBUG1("CSVPUtility::SetAudioCodecsForEmergencyL, VoIP profile")
       
   404         User::LeaveIfError( aVoipProfileId );
       
   405             
       
   406         // Get codec IDs from profile
       
   407         CRCSEProfileRegistry* profileRegistry = 
       
   408             CRCSEProfileRegistry::NewLC(); // CS:2
       
   409         profileRegistry->FindL( aVoipProfileId, *profile );
       
   410         CleanupStack::PopAndDestroy( profileRegistry ); // CS:1
       
   411         RArray< TUint32 > codecIds;
       
   412         CleanupClosePushL( codecIds ); // CS:2
       
   413         GetCodecIdsByVoIPProfileIdL( *profile, codecIds );
       
   414         
       
   415         // Set flags
       
   416         TBool isSetPCMA( EFalse );
       
   417         TBool isSetPCMU( EFalse );
       
   418 
       
   419         // Set capabilities
       
   420         CRCSEAudioCodecRegistry* codecRegistry = 
       
   421             CRCSEAudioCodecRegistry::NewLC(); // CS:3
       
   422         CRCSEAudioCodecEntry* codec = NULL;
       
   423         for( TInt j = 0; j < codecIds.Count(); j++ )
       
   424             {
       
   425             codec = CRCSEAudioCodecEntry::NewLC(); // CS:4
       
   426             codecRegistry->FindL( codecIds[j], *codec );
       
   427             MoCallCapabilitiesL( aAudioInStream, *profile, *codec );
       
   428             
       
   429             // Check G711
       
   430             if ( !codec->iMediaSubTypeName.CompareF( KAudioCodecPCMA ) )
       
   431                 {
       
   432                 isSetPCMA = ETrue;
       
   433                 }
       
   434             if ( !codec->iMediaSubTypeName.CompareF( KAudioCodecPCMU ) )
       
   435                 {
       
   436                 isSetPCMU = ETrue;
       
   437                 }
       
   438             CleanupStack::PopAndDestroy( codec ); // CS:3
       
   439             }
       
   440         CleanupStack::PopAndDestroy( codecRegistry ); // CS:2
       
   441         CleanupStack::PopAndDestroy( &codecIds ); // CS:1
       
   442         
       
   443 
       
   444         // Set G711 default capabilities if not set from profile
       
   445         if ( !isSetPCMA )
       
   446             {
       
   447             codec = CRCSEAudioCodecEntry::NewLC(); // CS:2
       
   448             codec->SetDefaultCodecValueSet( KAudioCodecPCMA() );
       
   449             MoCallCapabilitiesL( aAudioInStream, *profile, *codec );
       
   450             CleanupStack::PopAndDestroy( codec ); // CS:1
       
   451             }
       
   452         if ( !isSetPCMU )
       
   453             {
       
   454             codec = CRCSEAudioCodecEntry::NewLC(); // CS:2
       
   455             codec->SetDefaultCodecValueSet( KAudioCodecPCMU() );
       
   456             MoCallCapabilitiesL( aAudioInStream, *profile, *codec );
       
   457             CleanupStack::PopAndDestroy( codec ); // CS:1
       
   458             }
       
   459         }
       
   460     
       
   461     SetDtmfL( *profile, aAudioInStream );
       
   462     
       
   463     SetMediaQoSL( profile->iMediaQOS, aAudioInStream.Session() );
       
   464     
       
   465     // in Mo case, redundancy is never offered
       
   466     iRed = EFalse;
       
   467     
       
   468     // Set comfort noise for PCMA/PCMU & ILBC if CN provisioned and keep-alive
       
   469     if ( iCN )
       
   470         {
       
   471         SetComfortNoiseL( aAudioInStream );
       
   472         RemoveUnnecessaryCodecsL( aAudioInStream );
       
   473         SetCNKeepAliveL( aAudioInStream, aKeepAliveValue );
       
   474         }
       
   475     else
       
   476         {
       
   477         RemoveUnnecessaryCodecsL( aAudioInStream );
       
   478         SetKeepAliveL( aAudioInStream, aKeepAliveValue );
       
   479         }
       
   480     
       
   481     // Check RTCP for actual and bound stream as we do not have knowledge where
       
   482     // the actual RTP sink is residing
       
   483     CheckRtcpSettingL( profile->iRTCP, aAudioInStream );
       
   484     if ( aAudioInStream.BoundStream() )
       
   485         {
       
   486         CheckRtcpSettingL( profile->iRTCP, aAudioInStream.BoundStreamL() );
       
   487         }
       
   488     
       
   489     CleanupStack::PopAndDestroy( profile ); // CS:0
       
   490 
       
   491     // Leave if codec information was not found.
       
   492     if ( !aAudioInStream.Codecs().Count() )
       
   493         {
       
   494         SVPDEBUG1("CSVPUtility::SetAudioCodecsForEmergencyL KErrNotFound")
       
   495         User::Leave( KErrNotFound );
       
   496         }
       
   497     
       
   498     SVPDEBUG1("CSVPUtility::SetAudioCodecsForEmergencyL() Out")
       
   499     }
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // CSVPUtility::SetComfortNoiseL
       
   503 // ---------------------------------------------------------------------------
       
   504 //  
       
   505 void CSVPUtility::SetComfortNoiseL( CMceAudioStream& aAudioStream )
       
   506     {
       
   507     SVPDEBUG1("CSVPUtility::SetComfortNoiseL In");
       
   508     
       
   509     // fetch available codecs
       
   510     const RPointerArray<CMceAudioCodec>& codecs = aAudioStream.Codecs();
       
   511     
       
   512     // Comfort Noise must be enabled for bound stream codecs also
       
   513     CMceAudioStream& boundStream = 
       
   514         static_cast< CMceAudioStream& > ( aAudioStream.BoundStreamL() ); 
       
   515    
       
   516     // fetch bound stream codecs 
       
   517     const RPointerArray< CMceAudioCodec >& 
       
   518         boundCodecs = boundStream.Codecs();
       
   519     
       
   520     iCN = EFalse;
       
   521 
       
   522     for ( TInt z = 0; z < codecs.Count(); z++ )
       
   523         {
       
   524         if ( !codecs[ z ]->SdpName().CompareF( KCN ) && !iCN  )
       
   525             {
       
   526             SVPDEBUG1("CSVPUtility::SetComfortNoiseL CN found");
       
   527             // enable CN from main and bound stream
       
   528             aAudioStream.Codecs()[ z ]->SetStateL( CMceCodec::EEnabled );
       
   529             boundStream.Codecs()[ z ]->SetStateL( CMceCodec::EEnabled );
       
   530             // set flag to true, so CN is not removed from media attributes
       
   531             iCN = ETrue;
       
   532             
       
   533             // set also correct priority order for CN => lowest priority
       
   534             aAudioStream.Codecs()[ z ]->SetPreferenceL( codecs.Count() );
       
   535             }
       
   536         } 
       
   537     if ( iCN )
       
   538         {
       
   539         for ( TInt i = 0; i < codecs.Count(); i++ )
       
   540             {
       
   541             if( !codecs[ i ]->SdpName().CompareF( KPCMA ) || 
       
   542                 !codecs[ i ]->SdpName().CompareF( KPCMU ) ||
       
   543                 !codecs[ i ]->SdpName().CompareF( KILBC ) )
       
   544                 {
       
   545                 SVPDEBUG1("CSVPUtility::SetComfortNoiseL Setting VAD");
       
   546                 codecs[ i ]->EnableVAD( ETrue );
       
   547                 boundCodecs[ i ]->EnableVAD( ETrue );
       
   548                 }
       
   549             } 
       
   550         }
       
   551     SVPDEBUG1("CSVPUtility::SetComfortNoiseL Out");
       
   552     }
       
   553     
       
   554 // ---------------------------------------------------------------------------
       
   555 // CSVPUtility::SetDtmfL
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 void CSVPUtility::SetDtmfL( const CRCSEProfileEntry& aVoIPProfile, 
       
   559     CMceAudioStream& aAudioStream )
       
   560     {
       
   561     SVPDEBUG3( "CSVPUtility::SetDtmfL IB STATUS: %d OB STATUS: %d",
       
   562         aVoIPProfile.iInbandDTMF, aVoIPProfile.iOutbandDTMF )
       
   563     
       
   564     // If both on, not set or both off, prefer outband.
       
   565     if ( ( CRCSEAudioCodecEntry::EOn == aVoIPProfile.iInbandDTMF &&
       
   566            CRCSEAudioCodecEntry::EOn == aVoIPProfile.iOutbandDTMF ) ||
       
   567          ( CRCSEAudioCodecEntry::EOONotSet == aVoIPProfile.iInbandDTMF &&
       
   568            CRCSEAudioCodecEntry::EOONotSet == aVoIPProfile.iOutbandDTMF ) ||
       
   569          ( CRCSEAudioCodecEntry::EOff == aVoIPProfile.iInbandDTMF &&
       
   570            CRCSEAudioCodecEntry::EOff == aVoIPProfile.iOutbandDTMF ) )
       
   571         {
       
   572         SVPDEBUG1( "CSVPUtility::SetDtmfL IB/OB both enabled, not set or off" )
       
   573         
       
   574         iTelEv = ETrue;
       
   575         SetDtmfCodecOrderL( aAudioStream );
       
   576         }
       
   577     // Check inband enabled situation
       
   578     else if ( CRCSEAudioCodecEntry::EOn == aVoIPProfile.iInbandDTMF &&
       
   579               CRCSEAudioCodecEntry::EOff == aVoIPProfile.iOutbandDTMF )
       
   580         {
       
   581         SVPDEBUG1( "CSVPUtility::SetDtmfL OB DTMF OFF, IB DTMF ON" )
       
   582         
       
   583         iTelEv = EFalse;
       
   584         }
       
   585     // Check outband enabled situation
       
   586     else if ( CRCSEAudioCodecEntry::EOff == aVoIPProfile.iInbandDTMF &&
       
   587               CRCSEAudioCodecEntry::EOn == aVoIPProfile.iOutbandDTMF )
       
   588         {
       
   589         SVPDEBUG1( "CSVPUtility::SetDtmfL OB DTMF ON, IB DTMF OFF" )
       
   590         
       
   591         iTelEv = ETrue;
       
   592         SetDtmfCodecOrderL( aAudioStream );
       
   593         }
       
   594     // else all cases handled above.
       
   595     }
       
   596     
       
   597 //----------------------------------------------------------------------------
       
   598 // CSVPUtility::GetDTMFMode
       
   599 //----------------------------------------------------------------------------
       
   600 //    
       
   601 TBool CSVPUtility::GetDTMFMode()
       
   602     {
       
   603     SVPDEBUG2( "SVPUtility::GetDTMFMode iTelEv: %d", iTelEv )
       
   604     
       
   605     return iTelEv; // EFalse: DTMF Inband, ETrue: DTMF Outband
       
   606     }
       
   607 
       
   608 //----------------------------------------------------------------------------
       
   609 // CSVPUtility::SetDtmfMode
       
   610 //----------------------------------------------------------------------------
       
   611 //
       
   612 void CSVPUtility::SetDtmfMode( TBool aOutbandEnabled )
       
   613     {
       
   614     SVPDEBUG2( "SVPUtility::SetDtmfMode aOutbandEnabled: %d",
       
   615         aOutbandEnabled )
       
   616     
       
   617     iTelEv = aOutbandEnabled;
       
   618     }
       
   619 
       
   620 // ---------------------------------------------------------------------------
       
   621 // CSVPUtility::SetAudioCodecsMTL
       
   622 // ---------------------------------------------------------------------------
       
   623 //
       
   624 void CSVPUtility::SetAudioCodecsMTL( CRCSEProfileEntry& aVoIPProfile, 
       
   625                                      CMceMediaStream& aAudioStream,
       
   626                                      TInt aKeepAliveValue,
       
   627                                      TBool aSessionUpdateOngoing )
       
   628     {
       
   629     SVPDEBUG1("CSVPUtility::SetAudioCodecsMTL In")
       
   630     
       
   631     RArray< TUint32 > codecIds;
       
   632     CleanupClosePushL( codecIds );
       
   633     
       
   634     GetCodecIdsByVoIPProfileIdL( aVoIPProfile, codecIds );
       
   635     
       
   636     // create codec profile
       
   637     CRCSEAudioCodecEntry* codecprofile = 
       
   638                                     CRCSEAudioCodecEntry::NewLC();
       
   639     CRCSEAudioCodecRegistry* rCSEAudioCodec = 
       
   640                                     CRCSEAudioCodecRegistry::NewLC();
       
   641     
       
   642     // clearing the flag for next session 
       
   643     iCodecMatched = EFalse;  
       
   644     // Initialize round index variable (for the current session)
       
   645     iRoundIndex = 0;
       
   646  
       
   647     CMceAudioStream& audioStream =
       
   648         static_cast<CMceAudioStream&>( aAudioStream );
       
   649         
       
   650     const RPointerArray< CMceAudioCodec >& supportedCodecs = 
       
   651         audioStream.Codecs();
       
   652     
       
   653     const TInt suppCodecCount = supportedCodecs.Count();
       
   654     
       
   655     // loop as many times as needed 
       
   656     while ( iRoundIndex < suppCodecCount )
       
   657         {
       
   658         for ( TInt codecCnt = 0; codecCnt < codecIds.Count(); codecCnt++ )
       
   659             {
       
   660             if ( !iCodecMatched )
       
   661                 {
       
   662                 rCSEAudioCodec->FindL( codecIds[ codecCnt ], *codecprofile );
       
   663                 MtCallCapabilitiesL( audioStream, aVoIPProfile, *codecprofile );
       
   664                 }
       
   665             }
       
   666         
       
   667         if ( iCodecMatched )
       
   668             {
       
   669             SVPDEBUG1( "CSVPUtility::SetAudioCodecsMTL RED set" )
       
   670             SetRedundancyL( audioStream );
       
   671             SVPDEBUG1( "CSVPUtility::SetAudioCodecsMTL RED set done" )
       
   672             break;
       
   673             }
       
   674         else
       
   675             {
       
   676             iRoundIndex++;    
       
   677             }
       
   678         }
       
   679     
       
   680     if ( !iCodecMatched )
       
   681         {
       
   682         User::Leave( KSVPErrCodecMismatch );
       
   683         }
       
   684     
       
   685     SetMediaQoSL( aVoIPProfile.iMediaQOS, aAudioStream.Session() );
       
   686     
       
   687     // if outband DTMF offered, it's used even if inband is provisioned
       
   688     if ( DtmfOBInOffer( audioStream ) )
       
   689         {
       
   690         SetDtmfCodecOrderL( audioStream );
       
   691         iTelEv = ETrue;
       
   692         }
       
   693     else
       
   694         {
       
   695         SetDtmfL( aVoIPProfile, audioStream );
       
   696         }
       
   697     
       
   698     // set comfort noise if provisioned and offered by caller
       
   699     for ( TInt codecCnt = 0; codecCnt < codecIds.Count(); codecCnt++ )
       
   700         {
       
   701         // fetch codec profile
       
   702         rCSEAudioCodec->FindL( codecIds[ codecCnt ], *codecprofile );
       
   703         // set comfort noise
       
   704         HBufC8* tempSdpName = 
       
   705             HBufC8::NewLC( codecprofile->iMediaSubTypeName.Length() );
       
   706         TPtr8 ptr = tempSdpName->Des();
       
   707         ptr.Copy( codecprofile->iMediaSubTypeName );  
       
   708         if ( !tempSdpName->CompareF( KCN ) )
       
   709             {
       
   710             SVPDEBUG1( "CSVPUtility::SetAudioCodecsMTL - CN Provisioned" )
       
   711             SetComfortNoiseL( audioStream );    
       
   712             }
       
   713 
       
   714         CleanupStack::PopAndDestroy( tempSdpName );
       
   715         }
       
   716     
       
   717     RemoveUnnecessaryCodecsL( audioStream );
       
   718     
       
   719     // CN provisioned and in offer
       
   720     if ( iCN )
       
   721         {
       
   722         SVPDEBUG1( "CSVPUtility::SetAudioCodecsMTL - CN" )
       
   723         SetCNKeepAliveL( audioStream, aKeepAliveValue );
       
   724         }
       
   725     // CN not provisioned or offered
       
   726     else
       
   727         {
       
   728         SVPDEBUG1( "CSVPUtility::SetAudioCodecsMTL - No CN" )
       
   729         SetKeepAliveL( audioStream, aKeepAliveValue );
       
   730         }
       
   731     
       
   732     // Check RTCP for actual and bound stream as we do not have knowledge where
       
   733     // the actual RTP sink is residing
       
   734     CheckRtcpSettingL( aVoIPProfile.iRTCP, aAudioStream, aSessionUpdateOngoing );
       
   735     if ( aAudioStream.BoundStream() )
       
   736         {
       
   737         CheckRtcpSettingL( aVoIPProfile.iRTCP, aAudioStream.BoundStreamL(), aSessionUpdateOngoing );
       
   738         }
       
   739     
       
   740     // RCSE objects can be deleted
       
   741     CleanupStack::PopAndDestroy( 3, &codecIds );
       
   742          
       
   743     SVPDEBUG1( "CSVPUtility::SetAudioCodecsMTL Out" )
       
   744     }
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // CSVPUtility::DtmfOBInOffer
       
   748 // ---------------------------------------------------------------------------
       
   749 //   
       
   750 TBool CSVPUtility::DtmfOBInOffer( CMceAudioStream& aAudioStream )
       
   751 	{
       
   752 	SVPDEBUG1( "CSVPUtility::DtmfOBInOffer In" )
       
   753     const RPointerArray< CMceAudioCodec >& supportedCodecs = 
       
   754         aAudioStream.Codecs();
       
   755     TInt count = supportedCodecs.Count();
       
   756     while ( count-- )
       
   757         {
       
   758         if ( !supportedCodecs[ count ]->SdpName().CompareF( KTELEVENT ) )
       
   759             {
       
   760             SVPDEBUG1( "CSVPUtility::DtmfOBInOffer Outband DTMF in offer" )
       
   761             return ETrue;    
       
   762             }
       
   763         }
       
   764     return EFalse;
       
   765 	}
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // CSVPUtility::RemoveUnnecessaryCodecsL
       
   769 // ---------------------------------------------------------------------------
       
   770 //    
       
   771 void CSVPUtility::RemoveUnnecessaryCodecsL( CMceAudioStream& aAudioInStream )
       
   772     {
       
   773     SVPDEBUG1("CSVPUtility::RemoveUnnecessaryCodecs In");
       
   774     // if codec was not found, remove code from the codec array 
       
   775     if ( !iAMR )
       
   776         {
       
   777         SVPAudioUtility::RemoveCodecL( aAudioInStream, KAMR );
       
   778         }
       
   779     if ( !iPCMA )
       
   780         {
       
   781         SVPAudioUtility::RemoveCodecL( aAudioInStream, KPCMA );
       
   782         }
       
   783     if ( !iPCMU )
       
   784         {
       
   785         SVPAudioUtility::RemoveCodecL( aAudioInStream, KPCMU );
       
   786         }
       
   787     if ( !iILBC )
       
   788         {
       
   789         SVPAudioUtility::RemoveCodecL( aAudioInStream, KILBC );
       
   790         }
       
   791     if ( !iG729 )
       
   792         {
       
   793         SVPAudioUtility::RemoveCodecL( aAudioInStream, KG729 );
       
   794         }
       
   795     if ( !iTelEv )
       
   796         {
       
   797         SVPAudioUtility::RemoveCodecL( aAudioInStream, KTELEVENT );
       
   798         }
       
   799     if ( !iCN )
       
   800         {
       
   801         SVPAudioUtility::RemoveCodecL( aAudioInStream, KCN );
       
   802         iCN = EFalse;
       
   803         }
       
   804     if ( !iRed )
       
   805         {
       
   806         SVPAudioUtility::RemoveCodecL( aAudioInStream, KRED );
       
   807         }
       
   808     if ( !iAMRWB )
       
   809         {
       
   810         SVPAudioUtility::RemoveCodecL( aAudioInStream, KAMRWB );
       
   811         }
       
   812     
       
   813     // clear codec flags for next session
       
   814     iAMR = EFalse; 
       
   815     iPCMA = EFalse;
       
   816     iPCMU = EFalse;
       
   817     iILBC = EFalse;
       
   818     iG729 = EFalse;
       
   819     iRed = EFalse;
       
   820     iAMRWB = EFalse;
       
   821     
       
   822     SVPDEBUG1("CSVPUtility::RemoveUnnecessaryCodecs Out"); 
       
   823     }
       
   824     
       
   825 // ---------------------------------------------------------------------------
       
   826 // CSVPUtility::GetCodecIdsByVoIPProfileIdL
       
   827 // ---------------------------------------------------------------------------
       
   828 //
       
   829 void CSVPUtility::GetCodecIdsByVoIPProfileIdL( 
       
   830     const CRCSEProfileEntry& aProfile,
       
   831     RArray< TUint32 >& aCodecIds ) const
       
   832     {
       
   833     SVPDEBUG1("CSVPUtility::GetCodecIdsByVoIPProfileIdL IN");
       
   834     
       
   835     aCodecIds.Reset();
       
   836     
       
   837     const TInt codCount = aProfile.iPreferredCodecs.Count();
       
   838     for ( TInt codecCnt = 0; codecCnt < codCount; codecCnt++ )
       
   839         {
       
   840         // append codec id's in preference order
       
   841         aCodecIds.AppendL( aProfile.iPreferredCodecs[ codecCnt ] );
       
   842         }
       
   843     
       
   844     SVPDEBUG1("CSVPUtility::GetCodecIdsByVoIPProfileIdL OUT");
       
   845     }
       
   846 
       
   847 // ---------------------------------------------------------------------------
       
   848 // CSVPUtility::MtCallCapabilitiesL
       
   849 // ---------------------------------------------------------------------------
       
   850 //
       
   851 void CSVPUtility::MtCallCapabilitiesL( 
       
   852     CMceAudioStream& aAudioInStream, 
       
   853     const CRCSEProfileEntry& aVoIPProfile,
       
   854     const CRCSEAudioCodecEntry& aCodecProfile )
       
   855     {
       
   856     SVPDEBUG1( "CSVPUtility::MtCallCapabilitiesL IN" )
       
   857     
       
   858     // fetch the codecs mce supports
       
   859     const RPointerArray< CMceAudioCodec >& supportedCodecs = 
       
   860         aAudioInStream.Codecs();
       
   861     
       
   862     SVPDEBUG2( "CSVPUtility::MtCallCapabilitiesL: Supp. codec count: %d",
       
   863          supportedCodecs.Count() )
       
   864     
       
   865     HBufC8* tempSdpName = 
       
   866         HBufC8::NewLC( aCodecProfile.iMediaSubTypeName.Length() );
       
   867     
       
   868     TPtr8 ptr = tempSdpName->Des();
       
   869     ptr.Copy( aCodecProfile.iMediaSubTypeName );
       
   870     
       
   871     // compare offered codec to codec supported by app. 
       
   872     if ( *tempSdpName != supportedCodecs[ iRoundIndex ]->SdpName() ||
       
   873          !supportedCodecs[ iRoundIndex ]->SdpName().CompareF( KCN ) ||
       
   874          !supportedCodecs[ iRoundIndex ]->SdpName().CompareF( KTELEVENT ) ||
       
   875          !supportedCodecs[ iRoundIndex ]->SdpName().CompareF( KRED ) )
       
   876         {
       
   877         SVPDEBUG1( "CSVPUtility::MtCallCapabilitiesL do nothing" )
       
   878         }
       
   879     else
       
   880         {
       
   881         SVPDEBUG2( "CSVPUtility::MtCallCapabilitiesL Mediasubtypename: %S",
       
   882             &aCodecProfile.iMediaSubTypeName )
       
   883         SVPDEBUG2( "CSVPUtility::MtCallCapabilitiesL - ptime: %d",
       
   884             aCodecProfile.iPtime )
       
   885         SVPDEBUG2( "CSVPUtility::MtCallCapabilitiesL - maxptime: %d",
       
   886             aCodecProfile.iMaxptime )
       
   887         
       
   888         if ( aVoIPProfile.iStartMediaPort )
       
   889             {
       
   890             aAudioInStream.SetLocalMediaPortL( aVoIPProfile.iStartMediaPort );
       
   891             
       
   892             SVPDEBUG1( "CSVPUtility::MtCallCapabilitiesL start media port set" )
       
   893             }
       
   894 
       
   895         SVPDEBUG2( "CSVPUtility::MtCallCapabilitiesL codec ptime: %u",
       
   896             supportedCodecs[ iRoundIndex ]->PTime() )
       
   897         SVPDEBUG2( "CSVPUtility::MtCallCapabilitiesL codec maxptime: %u",
       
   898             supportedCodecs[ iRoundIndex ]->MaxPTime() )
       
   899         
       
   900         if ( aCodecProfile.iPtime >= 0 && 
       
   901              aCodecProfile.iMaxptime < 
       
   902              supportedCodecs[ iRoundIndex ]->PTime() )
       
   903             {   
       
   904             supportedCodecs[ iRoundIndex ]->SetPTime( aCodecProfile.iPtime );
       
   905             }
       
   906         
       
   907         if ( !aCodecProfile.iMediaSubTypeName.CompareF( KAudioCodecAMR ) )
       
   908             {
       
   909             // No actions taken in MT calls for AMR parameters. We accept
       
   910             // them as-is for improved IOP.
       
   911             iAMR = ETrue;
       
   912             } 
       
   913         
       
   914         if ( !aCodecProfile.iMediaSubTypeName.CompareF( KAudioCodecPCMA ) )
       
   915             {
       
   916             iPCMA = ETrue;
       
   917             }
       
   918 
       
   919         if ( !aCodecProfile.iMediaSubTypeName.CompareF( KAudioCodecPCMU ) )
       
   920             {
       
   921             iPCMU = ETrue;
       
   922             }
       
   923 
       
   924         if ( !aCodecProfile.iMediaSubTypeName.CompareF( KAudioCodeciLBC ) )
       
   925             {
       
   926             iILBC = ETrue;
       
   927             }
       
   928 
       
   929         if ( !aCodecProfile.iMediaSubTypeName.CompareF( KAudioCodecAMRWB  ) )
       
   930             {
       
   931             iAMRWB = ETrue;
       
   932             } 
       
   933 
       
   934         if ( !aCodecProfile.iMediaSubTypeName.CompareF( KAudioCodecG729 ) )
       
   935             {
       
   936             // AnnexB is not set if it is not in the offer. MO side may not
       
   937             // support AnnexB so we do not want to enforce it.
       
   938             iG729 = ETrue;
       
   939             }
       
   940         else
       
   941             {
       
   942             // set VAD if other than G729 codec case
       
   943             if ( CRCSEAudioCodecEntry::EOONotSet != aCodecProfile.iVAD )
       
   944                 {
       
   945                 SVPDEBUG1( "CSVPUtility::MtCallCapabilitiesL, codec and boundcodec VAD" );
       
   946                 // Setting VAD for codec
       
   947                 SetVADL( aAudioInStream, aCodecProfile.iVAD, *tempSdpName ); 
       
   948 
       
   949                 // Setting VAD also for bound codec
       
   950                 CMceAudioStream& boundStream = 
       
   951                     static_cast< CMceAudioStream& > ( aAudioInStream.BoundStreamL() ); 
       
   952                 SetVADL( boundStream, aCodecProfile.iVAD, *tempSdpName ); 
       
   953                 }
       
   954             }
       
   955 
       
   956         // Take the largest jitterbuffer size from settings. NB. this does
       
   957         // not actually take into account that we have codec spesific
       
   958         // jitterbuffer sizes and MCE has session level jitterbuffer size.
       
   959         // So we may end up using wrong jitterbuffer size if codec spesific
       
   960         // jitterbuffer settings are different amongst each other.
       
   961         if ( aCodecProfile.iJitterBufferSize > iJitterBufferSize )
       
   962             {
       
   963             iJitterBufferSize = aCodecProfile.iJitterBufferSize;
       
   964             }
       
   965 
       
   966         SVPDEBUG2( "CSVPUtility::MtCallCapabilitiesL iJitterBufferSize: %d",
       
   967             iJitterBufferSize )
       
   968 
       
   969         // set codec matched flag to ETrue, codec matched and set up
       
   970         iCodecMatched = ETrue;
       
   971         }
       
   972     
       
   973     CleanupStack::PopAndDestroy( tempSdpName );
       
   974     
       
   975     SVPDEBUG1( "CSVPUtility::MtCallCapabilitiesL OUT" )
       
   976     }
       
   977 
       
   978 // ---------------------------------------------------------------------------
       
   979 // CSVPUtility::SetRedundancyL
       
   980 // ---------------------------------------------------------------------------
       
   981 //
       
   982 void CSVPUtility::SetRedundancyL( CMceAudioStream& aAudioStream ) 
       
   983     {
       
   984     SVPDEBUG1( "CSVPUtility::SetRedundancyL In");
       
   985     const RPointerArray< CMceAudioCodec >& codecs = aAudioStream.Codecs();
       
   986     for ( TInt z = 0; z < codecs.Count(); z++ )
       
   987         {
       
   988         if ( !codecs[ z ]->SdpName().CompareF( KRED ) )
       
   989             {
       
   990             SVPDEBUG1( "CSVPUtility::SetRedundancyL Setting Red pref.");          
       
   991             // set preference 
       
   992             aAudioStream.Codecs()[ z ]->
       
   993                 SetPreferenceL( codecs.Count() );
       
   994             // set red flag so red media attribute is not removed
       
   995             iRed = ETrue;
       
   996             }
       
   997         }
       
   998     SVPDEBUG1( "CSVPUtility::SetRedundancyL Out");
       
   999     }
       
  1000 // ---------------------------------------------------------------------------
       
  1001 // CSVPUtility::MoCallCapabilitiesL
       
  1002 // ---------------------------------------------------------------------------
       
  1003 //
       
  1004 void CSVPUtility::MoCallCapabilitiesL( 
       
  1005                               CMceAudioStream& aAudioInStream, 
       
  1006                               const CRCSEProfileEntry& aVoIPProfile,
       
  1007                               const CRCSEAudioCodecEntry& aCodecProfile )
       
  1008     {
       
  1009     SVPDEBUG1("CSVPUtility::MoCallCapabilitiesL In")
       
  1010     
       
  1011     // fetch the codecs mce supports 
       
  1012     const RPointerArray< CMceAudioCodec >& supportedCodecs = 
       
  1013         aAudioInStream.Codecs();
       
  1014     
       
  1015     SVPDEBUG2("CSVPUtility::MoCallCapabilitiesL, Supported codec count: %d",
       
  1016         supportedCodecs.Count() );
       
  1017     
       
  1018     HBufC8* tempSdpName = 
       
  1019         HBufC8::NewLC( aCodecProfile.iMediaSubTypeName.Length() );
       
  1020         
       
  1021     SVPDEBUG2("CSVPUtility::MoCallCapabilitiesL Mediasubtypename: %S",
       
  1022         &aCodecProfile.iMediaSubTypeName );
       
  1023     
       
  1024     // go through the array and find Sdp name match
       
  1025     for ( TInt z = 0; z < supportedCodecs.Count(); z++ )
       
  1026         {
       
  1027         TPtr8 ptr = tempSdpName->Des();
       
  1028         ptr.Copy( aCodecProfile.iMediaSubTypeName );
       
  1029           
       
  1030         if ( *tempSdpName == supportedCodecs[ z ]->SdpName() )
       
  1031             {
       
  1032             // first setting audio capabilities common for all codecs
       
  1033             
       
  1034             // set codec priority order
       
  1035             SVPDEBUG2("CSVPUtility::MoCallCapabilitiesL Codec order: %d",
       
  1036                 iPreferredCodec );
       
  1037             
       
  1038             supportedCodecs[ z ]->SetPreferenceL( iPreferredCodec++ );
       
  1039             
       
  1040             // set media port
       
  1041             if ( aVoIPProfile.iStartMediaPort )
       
  1042                 {
       
  1043                 aAudioInStream.SetLocalMediaPortL( aVoIPProfile.iStartMediaPort );
       
  1044                 SVPDEBUG1("CSVPUtility::MoCallCapabilitiesL start media port set");
       
  1045                 }
       
  1046             
       
  1047             // set VAD    
       
  1048             if ( CRCSEAudioCodecEntry::EOONotSet != aCodecProfile.iVAD )
       
  1049                 {
       
  1050                 SVPDEBUG1( "CSVPUtility::MoCallCapabilitiesL Setting codec VAD" );
       
  1051 
       
  1052                 // Setting VAD for codec
       
  1053                 SetVADL( aAudioInStream, aCodecProfile.iVAD, *tempSdpName ); 
       
  1054 
       
  1055                 SVPDEBUG1( "CSVPUtility::MoCallCapabilitiesL Setting bound VAD" );
       
  1056                 // Setting VAD also for bound codec
       
  1057                 CMceAudioStream& boundStream = 
       
  1058                     static_cast< CMceAudioStream& > ( aAudioInStream.BoundStreamL() ); 
       
  1059                 SetVADL( boundStream, aCodecProfile.iVAD, *tempSdpName ); 
       
  1060                 }
       
  1061             
       
  1062             // set maxptime
       
  1063             if ( aCodecProfile.iMaxptime >= 0 ) 
       
  1064                 {
       
  1065                 supportedCodecs[ z ]->SetMaxPTime( aCodecProfile.iMaxptime );
       
  1066                 
       
  1067                 SVPDEBUG2("CSVPUtility::MoCallCapabilitiesL iMaxptime: %d",
       
  1068                     aCodecProfile.iMaxptime );
       
  1069                 }
       
  1070             
       
  1071             // set ptime
       
  1072             if ( aCodecProfile.iPtime >= 0 )     
       
  1073                 {
       
  1074                 SVPDEBUG2("CSVPUtility::MoCallCapabilitiesL, PTime: %d",
       
  1075                     aCodecProfile.iPtime );
       
  1076                 
       
  1077                 supportedCodecs[ z ]->SetPTime( aCodecProfile.iPtime );
       
  1078                 } 
       
  1079             
       
  1080             if ( !aCodecProfile.iMediaSubTypeName.CompareF( KAudioCodecAMR ) )
       
  1081                 {
       
  1082                 iAMR = ETrue;
       
  1083                 
       
  1084                 // AMR specific settings: mode-set, mode-change-period,
       
  1085                 // mode-change-neighbor and octet alignment vs. bw-efficient
       
  1086                 // mode
       
  1087                 SetAMRParameters( aAudioInStream, aCodecProfile, z );
       
  1088                 if ( CRCSEAudioCodecEntry::EOn == aCodecProfile.iOctetAlign )
       
  1089                     {
       
  1090                     // use octet-alignment for MO call
       
  1091                     supportedCodecs[ z ]->SetCodecMode(
       
  1092                         EMceOctetAligned );
       
  1093                     }
       
  1094                 }
       
  1095             
       
  1096             if ( !aCodecProfile.iMediaSubTypeName.
       
  1097                  CompareF( KAudioCodecPCMA ) )
       
  1098                 {
       
  1099                 iPCMA = ETrue;
       
  1100                 }
       
  1101             if ( !aCodecProfile.iMediaSubTypeName.
       
  1102                  CompareF( KAudioCodecPCMU ) )
       
  1103                 {
       
  1104                 iPCMU = ETrue;
       
  1105                 }
       
  1106             if ( !aCodecProfile.iMediaSubTypeName.
       
  1107                  CompareF( KAudioCodeciLBC ) )
       
  1108                 {
       
  1109                 iILBC = ETrue;
       
  1110                 // Set mode according to mode-set.
       
  1111                 if ( aCodecProfile.iModeSet.Count() )
       
  1112                     {
       
  1113                     if ( KSvpilbcMode20ms == aCodecProfile.iModeSet[0] )
       
  1114                         {
       
  1115                         supportedCodecs[ z ]->SetBitrate(
       
  1116                             KMceiLBCLevel20Bitrate );
       
  1117                         }
       
  1118                     else if( KSvpilbcMode30ms == aCodecProfile.iModeSet[0] )
       
  1119                         {
       
  1120                         supportedCodecs[ z ]->SetBitrate(
       
  1121                             KMceiLBCLevel30Bitrate );
       
  1122                         }
       
  1123                     }
       
  1124                 }
       
  1125             
       
  1126             if ( !aCodecProfile.iMediaSubTypeName.
       
  1127                  CompareF( KAudioCodecG729 ) )
       
  1128                 {
       
  1129                 iG729 = ETrue;
       
  1130                 // set annexb
       
  1131                 if ( CRCSEAudioCodecEntry::EOn == aCodecProfile.iAnnexb )
       
  1132                     {
       
  1133                     supportedCodecs[ z ]->EnableVAD( ETrue );
       
  1134                     }
       
  1135                 }
       
  1136      
       
  1137             if ( !aCodecProfile.iMediaSubTypeName.CompareF( KAudioCodecAMRWB ) )
       
  1138                 {
       
  1139                 iAMRWB = ETrue;
       
  1140                 
       
  1141                 // AMR-WB specific settings: mode-set, mode-change-period,
       
  1142                 // mode-change-neighbor and octet alignment vs. bw-efficient
       
  1143                 // mode
       
  1144                 SetAmrWbParameters( aAudioInStream, aCodecProfile, z );
       
  1145                 if ( CRCSEAudioCodecEntry::EOn == aCodecProfile.iOctetAlign )
       
  1146                     {
       
  1147                     // use octet-alignment for MO call
       
  1148                     supportedCodecs[ z ]->SetCodecMode(
       
  1149                         EMceOctetAligned );
       
  1150                     }
       
  1151                 }
       
  1152 
       
  1153 			// Take the largest jitterbuffer size from settings. NB. this does
       
  1154             // not actually take into account that we have codec spesific
       
  1155             // jitterbuffer sizes and MCE has session level jitterbuffer size.
       
  1156             // So we may end up using wrong jitterbuffer size if codec spesific
       
  1157             // jitterbuffer settings are different amongst each other.
       
  1158             if ( aCodecProfile.iJitterBufferSize > iJitterBufferSize )
       
  1159                 {
       
  1160                 iJitterBufferSize = aCodecProfile.iJitterBufferSize;
       
  1161                 }
       
  1162             
       
  1163             SVPDEBUG2( "CSVPUtility::MoCallCapabilitiesL iJitterBufferSize: %d",
       
  1164                 iJitterBufferSize );
       
  1165             }   
       
  1166         }
       
  1167     CleanupStack::PopAndDestroy( tempSdpName );
       
  1168     
       
  1169     SVPDEBUG1( "CSVPUtility::MoCallCapabilitiesL OUT" );
       
  1170     }
       
  1171     
       
  1172 
       
  1173 // ---------------------------------------------------------------------------
       
  1174 // CSVPUtility::SetAMRParameters
       
  1175 // ---------------------------------------------------------------------------
       
  1176 //
       
  1177 void CSVPUtility::SetAMRParameters( CMceAudioStream& aAudioInStream, 
       
  1178                                     const CRCSEAudioCodecEntry& aCodecProfile,
       
  1179                                     TInt aCodecNumber )
       
  1180     {
       
  1181     SVPDEBUG1( "CSVPUtility::SetAMRParameters Entry" )
       
  1182 
       
  1183     TUint allowedBitrates( 0 );
       
  1184     
       
  1185     // Set correct mode-set (default 0,1,2,3,4,5,6,7):
       
  1186     const RArray< TUint32 >& modeSetArray = aCodecProfile.iModeSet;
       
  1187     for ( TInt i = 0; i < modeSetArray.Count(); i++ )
       
  1188         {
       
  1189         TUint value = modeSetArray[ i ];
       
  1190         switch ( value )
       
  1191             {
       
  1192             case 0: { allowedBitrates |= KMceAllowedAmrNbBitrate475;  break; }
       
  1193             case 1: { allowedBitrates |= KMceAllowedAmrNbBitrate515;  break; }
       
  1194             case 2: { allowedBitrates |= KMceAllowedAmrNbBitrate590;  break; }
       
  1195             case 3: { allowedBitrates |= KMceAllowedAmrNbBitrate670;  break; }
       
  1196             case 4: { allowedBitrates |= KMceAllowedAmrNbBitrate740;  break; }
       
  1197             case 5: { allowedBitrates |= KMceAllowedAmrNbBitrate795;  break; }
       
  1198             case 6: { allowedBitrates |= KMceAllowedAmrNbBitrate102;  break; }
       
  1199             case 7: { allowedBitrates |= KMceAllowedAmrNbBitrate122;  break; }
       
  1200             }
       
  1201             
       
  1202         SVPDEBUG3( "CSVPUtility::SetAMRParameters round %d, value: %u",
       
  1203             i, value )
       
  1204         SVPDEBUG2( "CSVPUtility::SetAMRParameters allowedBitrates 0x%x",
       
  1205             allowedBitrates )
       
  1206         }
       
  1207     
       
  1208     if ( !allowedBitrates )
       
  1209         {
       
  1210         allowedBitrates = KMceAllowedAmrNbBitrateAll;
       
  1211         }
       
  1212     
       
  1213     SVPDEBUG2( "CSVPUtility::SetAMRParameters mode-set 0x%x", allowedBitrates )
       
  1214     
       
  1215     if ( 2 == aCodecProfile.iModeChangePeriod )
       
  1216         {
       
  1217         // Set correct mode-change-period (default == 1):
       
  1218         allowedBitrates |= KMceAllowedAmrNbChangePeriod2;
       
  1219         }
       
  1220 
       
  1221     // Set correct mode-change-neighbor (default == 0)
       
  1222     if ( CRCSEAudioCodecEntry::EOn == aCodecProfile.iModeChangeNeighbor )
       
  1223         {
       
  1224         allowedBitrates |= KMceAllowedAmrNbChangeNeighbor1;
       
  1225         }
       
  1226 
       
  1227     aAudioInStream.Codecs()[ aCodecNumber ]->SetAllowedBitrates(
       
  1228         allowedBitrates );
       
  1229 
       
  1230     SVPDEBUG2( "CSVPUtility::SetAMRParameters, Exit 0x%x", allowedBitrates )
       
  1231     }
       
  1232     
       
  1233 // ---------------------------------------------------------------------------
       
  1234 // CSVPUtility::GetCCPError
       
  1235 // ---------------------------------------------------------------------------
       
  1236 //
       
  1237 TCCPError CSVPUtility::GetCCPError( TInt& aErrorCode, TCCPTone& aTone  ) const
       
  1238     {
       
  1239     SVPDEBUG2( "CSVPUtility::GetCCPError aErrorCode: %d", aErrorCode )
       
  1240     
       
  1241     // See ccpdefs.h - this may require additional checking so that the
       
  1242     // tones are really correct.
       
  1243     TCCPError error = ECCPErrorNone;
       
  1244     TCCPTone tone = ECCPNoSoundSequence;
       
  1245    
       
  1246     switch ( aErrorCode )
       
  1247         {    
       
  1248         case KSVPDeclineVal:
       
  1249         case KSVPBusyHereVal:
       
  1250         case KSVPBusyEverywhereVal:
       
  1251             {
       
  1252             error = ECCPErrorBusy;  
       
  1253             tone = ECCPToneUserBusy;
       
  1254             break;
       
  1255             }
       
  1256             
       
  1257         case KSVPLoopDetectedVal:
       
  1258         case KSVPTooManyHopsVal:
       
  1259         case KSVPServerInternalErrorVal:
       
  1260         case KSVPNotImplementedVal:
       
  1261         case KSVPBadGatewayVal:
       
  1262         case KSVPServiceUnavailableVal:
       
  1263         case KSVPServerTimeoutVal:
       
  1264         case KSVPVersionNotSupportedVal:
       
  1265         case KSVPMessageTooLargeVal:
       
  1266         case KSVPPreconditionFailureVal:
       
  1267             {
       
  1268             error = ECCPErrorNetworkOutOfOrder;   
       
  1269             tone = ECCPToneCongestion;
       
  1270             break;
       
  1271             }
       
  1272            
       
  1273         case KSVPUseProxyVal:
       
  1274         case KSVPAlternativeServiceVal:
       
  1275             {
       
  1276             error = ECCPErrorNotReached; 
       
  1277             tone = ECCPToneSpecialInformation;
       
  1278             break;
       
  1279             }
       
  1280     
       
  1281                    
       
  1282         case KSVPRequestUriTooLongVal:
       
  1283         case KSVPUnsupportedUriSchemeVal:
       
  1284         case KSVPAddressIncompleteVal:
       
  1285         case KSVPAmbiguousVal:
       
  1286             {
       
  1287             error = ECCPErrorInvalidURI;   
       
  1288             tone = ECCPToneSpecialInformation;
       
  1289             break;
       
  1290             } 
       
  1291             
       
  1292         case KSVPBadRequestVal:
       
  1293         case KSVPMethodNotAllowedVal:
       
  1294         case KSVPUnsupportedMediaTypeVal:
       
  1295         case KSVP406NotAcceptableVal:
       
  1296         case KSVPRequestEntityTooLargeVal:
       
  1297         case KSVPBadExtensionVal:
       
  1298         case KSVPExtensionRequiredVal:
       
  1299         case KSVPCallDoesNotExistVal:
       
  1300         case KSVPNotAcceptableHereVal:
       
  1301         case KSVPNotAcceptableVal:
       
  1302             {
       
  1303             error = ECCPErrorNotAcceptable; 
       
  1304             tone = ECCPToneRadioPathNotAvailable;
       
  1305             break;
       
  1306             }
       
  1307         
       
  1308         case KSVPRequestTerminatedVal:
       
  1309         case KSVPNotFoundVal:
       
  1310         case KSVPTemporarilyUnavailableVal:
       
  1311             {
       
  1312             error = ECCPErrorNotResponding;  
       
  1313             tone = ECCPToneUserBusy;
       
  1314             break;
       
  1315             }
       
  1316             	
       
  1317         case KSVPMovedPermanentlyVal:
       
  1318         case KSVPGoneVal:
       
  1319         case KSVPDoesNotExistAnywhereVal:
       
  1320             {
       
  1321             error = ECCPErrorMovedPermanently; 
       
  1322             tone = ECCPToneRadioPathNotAvailable;
       
  1323             break; 
       
  1324             }
       
  1325         
       
  1326         case KSVPRequestTimeoutVal:
       
  1327             {
       
  1328             error = ECCPErrorConnectionErrorRedial;  
       
  1329             tone = ECCPToneSpecialInformation;
       
  1330             break;
       
  1331             }
       
  1332        
       
  1333         case KSVPUnauthorizedVal:
       
  1334         case KSVPPaymentRequiredVal:
       
  1335         case KSVPForbiddenVal:
       
  1336         case KSVPProxyAuthenticationRequiredVal:
       
  1337         case KSVPIntervalTooBriefVal:
       
  1338         case KSVPBadEventVal:
       
  1339         case KSVPSecurityAgreementRequiredVal:
       
  1340 		    {
       
  1341             error = ECCPErrorNoService;
       
  1342             tone = ECCPToneCongestion;
       
  1343             break;
       
  1344             }
       
  1345                   
       
  1346         default:
       
  1347             {   
       
  1348             if ( 299 < aErrorCode && 400 > aErrorCode )
       
  1349                 {
       
  1350                 // Received a 3XX response not handled above
       
  1351                 error = ECCPErrorNotReached;
       
  1352                 break;
       
  1353                 }
       
  1354             else if ( 399 < aErrorCode && 500 > aErrorCode )
       
  1355                 {
       
  1356                 // Received a 4XX response not handled above
       
  1357                 error = ECCPErrorNotAcceptable;
       
  1358                 tone = ECCPToneRadioPathNotAvailable;
       
  1359                 break;
       
  1360                 }
       
  1361             else if ( 499 < aErrorCode && 600 > aErrorCode )
       
  1362                 {
       
  1363                 // Received a 5XX response not handled above
       
  1364                 error = ECCPErrorNetworkOutOfOrder;
       
  1365                 tone = ECCPToneCongestion;
       
  1366                 break;
       
  1367                 }
       
  1368             else if ( 599 < aErrorCode && 700 > aErrorCode )
       
  1369                 {
       
  1370                 // Received a 6XX response not handled above
       
  1371                 error = ECCPGlobalFailure;
       
  1372                 tone = ECCPToneUserBusy;
       
  1373                 break;
       
  1374                 }
       
  1375             else 
       
  1376                 {
       
  1377                 SVPDEBUG1("CSVPUtility::GetCCPError Not an error code")
       
  1378                 aErrorCode = KErrNone;
       
  1379                 tone = ECCPNoSoundSequence;
       
  1380                 break;
       
  1381                 }  
       
  1382             }
       
  1383         }
       
  1384     SVPDEBUG3( "CSVPUtility::GetCCPError error: %d, tone: %d",
       
  1385         error, tone )
       
  1386     
       
  1387     aTone = tone;
       
  1388     return error;
       
  1389     }
       
  1390     
       
  1391 
       
  1392 // ---------------------------------------------------------------------------
       
  1393 // CSVPUtility::LogVoipEventL
       
  1394 // ---------------------------------------------------------------------------
       
  1395 //
       
  1396 void CSVPUtility::LogVoipEventL( TInt aErrorCode, TUint32 aSipProfileId,
       
  1397     const TDesC& aRemoteURI, const TDesC& aMethod ) const
       
  1398     {  
       
  1399     SVPDEBUG1( "CSVPUtility::LogVoipEventL In" );
       
  1400     HBufC* remote = NULL; 
       
  1401 
       
  1402     if ( iVoipEventLogger )
       
  1403         {            
       
  1404         // set the profile id and remote URI to the error text parameter
       
  1405         // tab is used as value delimiter
       
  1406         TBuf<KSVPTempStringlength> entryArguments;
       
  1407         entryArguments.AppendNum( aSipProfileId );
       
  1408         entryArguments.Append( KSVPLogFieldDelimiter );
       
  1409         
       
  1410         // parse "sip:" away from the remote address
       
  1411         if ( aRemoteURI.Length() > 0 )
       
  1412             {
       
  1413             remote = aRemoteURI.AllocLC();
       
  1414 
       
  1415             if ( 0 == remote->Find( KSVPSipPrefix2 ) )
       
  1416                 {
       
  1417                 remote->Des().Delete( 0, KSVPSipPrefixLength );
       
  1418                 }
       
  1419                 
       
  1420             entryArguments.Append( *remote );                
       
  1421         
       
  1422             CleanupStack::PopAndDestroy( remote );    
       
  1423             }                     
       
  1424         else
       
  1425             {
       
  1426             entryArguments.Append( aRemoteURI );
       
  1427             }
       
  1428         
       
  1429         entryArguments.Append( KSVPLogFieldDelimiter );
       
  1430         entryArguments.Append( aMethod );      
       
  1431 
       
  1432         CVoipErrorEntry* entry = CVoipErrorEntry::NewLC( aErrorCode, 
       
  1433                                                          entryArguments );
       
  1434         iVoipEventLogger->WriteError( *entry );
       
  1435 
       
  1436         CleanupStack::PopAndDestroy( entry );
       
  1437         
       
  1438         SVPDEBUG3( "CSVPUtility::LogVoipEventL: \
       
  1439                     err: %d, aMethod: %S", aErrorCode, &aMethod );       
       
  1440         
       
  1441         }
       
  1442 
       
  1443     SVPDEBUG1( "CSVPUtility::LogVoipEventL Out" );
       
  1444     }
       
  1445 
       
  1446 
       
  1447 // ---------------------------------------------------------------------------
       
  1448 // CSVPUtility::GetDtmfEvent
       
  1449 // ---------------------------------------------------------------------------
       
  1450 //
       
  1451 MCCPDTMFObserver::TCCPDtmfEvent CSVPUtility::GetDtmfEvent( 
       
  1452     MMceDtmfObserver::TMceDtmfEvent aEvent,
       
  1453     TBool aDtmfStringSending )
       
  1454     {
       
  1455     SVPDEBUG1( "CSVPUtility::GetDtmfEvent In" )
       
  1456     
       
  1457     MCCPDTMFObserver::TCCPDtmfEvent event = MCCPDTMFObserver::ECCPDtmfUnknown;
       
  1458     
       
  1459     switch ( aEvent )
       
  1460         {
       
  1461         case MMceDtmfObserver::EDtmfSendStarted:
       
  1462             {
       
  1463             if ( aDtmfStringSending )
       
  1464                 {
       
  1465                 SVPDEBUG1( "CSVPUtility::GetDtmfEvent ECCPDtmfSequenceStart" )
       
  1466                 
       
  1467                 event = MCCPDTMFObserver::ECCPDtmfSequenceStart;
       
  1468                 }
       
  1469             else
       
  1470                 {
       
  1471                 SVPDEBUG1( "CSVPUtility::GetDtmfEvent ECCPDtmfManualStart" )
       
  1472                 
       
  1473                 event = MCCPDTMFObserver::ECCPDtmfManualStart;  
       
  1474                 }
       
  1475             
       
  1476             break;            
       
  1477             }
       
  1478         case MMceDtmfObserver::EDtmfSendCompleted:
       
  1479             {
       
  1480             if ( aDtmfStringSending )
       
  1481                 {
       
  1482                 SVPDEBUG1( "CSVPUtility::GetDtmfEvent ECCPDtmfStringSendingCompleted" )
       
  1483                 
       
  1484                 event = MCCPDTMFObserver::ECCPDtmfStringSendingCompleted;
       
  1485                 }
       
  1486             // else NOP
       
  1487             
       
  1488             break;                  
       
  1489             } 
       
  1490         default:
       
  1491             {
       
  1492             // This block should never be reached.
       
  1493             SVPDEBUG1( "CSVPUtility::GetDtmfEvent default case!" )
       
  1494             
       
  1495             event = MCCPDTMFObserver::ECCPDtmfUnknown;
       
  1496             break;
       
  1497             }
       
  1498         }
       
  1499     
       
  1500     return event;
       
  1501     }
       
  1502 
       
  1503 
       
  1504        
       
  1505 // ---------------------------------------------------------------------------
       
  1506 // CSVPUtility::SetProvisioningDataL
       
  1507 // ---------------------------------------------------------------------------
       
  1508 //
       
  1509 void CSVPUtility::SetProvisioningDataL( CRCSEProfileEntry& aVoipProfile,
       
  1510                      CDesC8Array& aUserAgentHeaders, 
       
  1511                      TUint32& aSecurityStatus,
       
  1512                      TBuf<KSVPMaxTerminalTypeLength>& aTerminalType,
       
  1513                      TBuf<KSVPWlanMacAddressLength>& aWlanMACAddress ) const
       
  1514     {
       
  1515     SVPDEBUG1("CSVPUtility::SetProvisioningDataL In" );
       
  1516 
       
  1517     // fetch security status
       
  1518     aSecurityStatus = aVoipProfile.iSecureCallPreference;
       
  1519     
       
  1520     SVPDEBUG2("CSVPUtility::SetProvisioningDataL: aSecurityStatus = %d",
       
  1521             aSecurityStatus );
       
  1522 
       
  1523     TBool terminalTypeEnabled = aVoipProfile.iSIPVoIPUAHTerminalType;
       
  1524      SVPDEBUG2("CSVPUtility::SetProvisioningDataL: terminalTypeEnabled = %d",
       
  1525             terminalTypeEnabled );
       
  1526     
       
  1527     TBool wlanMacEnabled = aVoipProfile.iSIPVoIPUAHeaderWLANMAC;
       
  1528     
       
  1529       SVPDEBUG2("CSVPUtility::SetProvisioningDataL: wlanMacEnabled = %d",
       
  1530             wlanMacEnabled );
       
  1531             
       
  1532     // temp descriptor for user-agent header
       
  1533     TBuf< KSVPMaxUAFreeTextLength > uaHeaderFreeString;
       
  1534     
       
  1535      // SIP VoIP User Agent header string
       
  1536     uaHeaderFreeString = aVoipProfile.iSIPVoIPUAHeaderString;
       
  1537     
       
  1538     // UA header found, append header name 
       
  1539     TBuf8<KSVPTempStringlength> userAgentString;
       
  1540     userAgentString.Append( KSVPUserAgent );
       
  1541     
       
  1542     // add terminat type
       
  1543     if( terminalTypeEnabled )
       
  1544         {
       
  1545         userAgentString.Append( KSVPSpaceMark );
       
  1546         userAgentString.Append( aTerminalType );
       
  1547         SVPDEBUG2("CSVPUtility::SetProvisioningDataL: aTerminalType = %S",
       
  1548             &aTerminalType );
       
  1549         userAgentString.Append( KSVPSpaceMark );
       
  1550         }
       
  1551     // add wlan mac address
       
  1552     if( wlanMacEnabled )
       
  1553         {
       
  1554         userAgentString.Append( aWlanMACAddress );
       
  1555         SVPDEBUG2("CSVPUtility::SetProvisioningDataL: aWlanMACAddress = %S",
       
  1556             &aWlanMACAddress );
       
  1557         userAgentString.Append( KSVPSpaceMark );
       
  1558         }
       
  1559     // add free string
       
  1560     if( 0 != uaHeaderFreeString.Length() )  
       
  1561         {
       
  1562         // append user agent header string part
       
  1563         userAgentString.Append( uaHeaderFreeString );
       
  1564         SVPDEBUG2("CSVPUtility::SetProvisioningDataL:\
       
  1565          uaHeaderFreeString = %S", &uaHeaderFreeString );
       
  1566         userAgentString.Append( KSVPSpaceMark );
       
  1567         } 
       
  1568     
       
  1569     // match language code and add to user-agent header    
       
  1570     TInt langCode =  User::Language();
       
  1571     TBuf< KSVPMaxLangCodeLength > languageTag; 
       
  1572     if ( langCode > 0 )
       
  1573         {
       
  1574         SVPDEBUG2("CSVPUtility::SetProvisioningDataL\
       
  1575          Language code: %d", langCode );
       
  1576         
       
  1577         MatchLanguageTags( langCode, languageTag );
       
  1578         
       
  1579         if ( languageTag.Length() != 0 )
       
  1580             {
       
  1581             SVPDEBUG2("CSVPUtility::SetProvisioninDataL ISO\
       
  1582             stanard language code: %S", &languageTag );
       
  1583             // add language tag to user agent string
       
  1584             userAgentString.Append( KSVPOpeningBracket );
       
  1585             userAgentString.Append( languageTag ); 
       
  1586             userAgentString.Append( KSVPClosingBracket );
       
  1587             }
       
  1588         }
       
  1589      
       
  1590     // add collected User-Agent string to header
       
  1591     aUserAgentHeaders.AppendL( userAgentString );
       
  1592     
       
  1593     // add accept language header
       
  1594     TBuf8<KSVPAcceptLangStringLength> acceptLanguageString;
       
  1595     acceptLanguageString.Append( KSVPAcceptLanguage );
       
  1596     acceptLanguageString.Append( languageTag );
       
  1597     
       
  1598     // add expires header
       
  1599      // add accept language header
       
  1600     TBuf8<KSVPExpiresHeaderLength> expiresHeaderString;
       
  1601     expiresHeaderString.Append( KSVPExpiresHeader );
       
  1602     expiresHeaderString.Append( KSVPExpires );
       
  1603     
       
  1604     aUserAgentHeaders.AppendL( acceptLanguageString );
       
  1605     aUserAgentHeaders.AppendL( expiresHeaderString );
       
  1606         
       
  1607     // Add Privacy header
       
  1608     TBuf8<KSVPPrivacyLength> privacyString;
       
  1609     privacyString.Append( KSVPPrivacy );
       
  1610 
       
  1611     if ( IsCLIROnL() )
       
  1612         {
       
  1613         privacyString.Append( KSVPId );
       
  1614         }
       
  1615     else
       
  1616         {
       
  1617         privacyString.Append( KSVPNone );
       
  1618         }
       
  1619     aUserAgentHeaders.AppendL( privacyString );
       
  1620     }
       
  1621 
       
  1622 // ---------------------------------------------------------------------------
       
  1623 // CSVPUtility::IsCLIROnL
       
  1624 // ---------------------------------------------------------------------------
       
  1625 //
       
  1626 TBool CSVPUtility::IsCLIROnL() const
       
  1627     {
       
  1628 
       
  1629     TInt valueCLIR( KSVPClirOff ); 
       
  1630     TBool clirOn = EFalse;
       
  1631 
       
  1632     CRepository* repository = NULL;
       
  1633     repository = CRepository::NewL( KCRUidRichCallSettings );
       
  1634     repository->Get( KRCSEClir, valueCLIR );
       
  1635     delete repository;
       
  1636     repository = NULL;
       
  1637 
       
  1638     SVPDEBUG2("CSVPUtility::IsCLIROnL valueCLIR : %d", valueCLIR );
       
  1639     if ( KSVPClirOn == valueCLIR )
       
  1640         {
       
  1641         // 0 = KRCSEClirOff
       
  1642         clirOn = ETrue;
       
  1643         }
       
  1644     else
       
  1645         {
       
  1646         // 1 = KRCSEClirOn or 2 = KRCSEClirDefault
       
  1647         clirOn = EFalse;
       
  1648         }
       
  1649 
       
  1650     SVPDEBUG2("CSVPUtility::IsCLIROnL returns %d", clirOn);
       
  1651     return clirOn;
       
  1652     }
       
  1653 
       
  1654 // ---------------------------------------------------------------------------
       
  1655 // CSVPUtility::SetMoFromHeaderLC
       
  1656 // ---------------------------------------------------------------------------
       
  1657 //
       
  1658 HBufC8* CSVPUtility::SetMoFromHeaderLC( TUint aSecurityStatus )
       
  1659     {
       
  1660 
       
  1661     HBufC8* fromheader = NULL;
       
  1662 
       
  1663     if ( IsCLIROnL() )
       
  1664         {
       
  1665         SVPDEBUG1("CSVPMoSession::SetMoFromHeaderLC CLIR is ON");
       
  1666         if ( KSVPStatusNonSecure == aSecurityStatus )
       
  1667             {
       
  1668         	fromheader = HBufC8::NewLC(KSVPMyAnonymousAddress.iTypeLength);
       
  1669         	fromheader->Des().Append( KSVPMyAnonymousAddress );
       
  1670             }
       
  1671         else
       
  1672             {
       
  1673         	fromheader = HBufC8::NewLC(KSVPMyAnonymousSecAddress.iTypeLength);
       
  1674         	fromheader->Des().Append( KSVPMyAnonymousSecAddress );
       
  1675             }
       
  1676         }
       
  1677     else
       
  1678         {
       
  1679         SVPDEBUG1("CSVPMoSession::SetMoFromHeaderLC CLIR is OFF");
       
  1680     	fromheader = HBufC8::NewLC(KSVPEmpty.iTypeLength);
       
  1681     	fromheader->Des().Append( KSVPEmpty );
       
  1682         }
       
  1683 
       
  1684     return fromheader;
       
  1685     }
       
  1686 
       
  1687 // ---------------------------------------------------------------------------
       
  1688 // CSVPUtility::AddPPreferredIdentityToUserHeaders
       
  1689 // ---------------------------------------------------------------------------
       
  1690 //
       
  1691 void CSVPUtility::AddPPreferredIdentityToUserHeadersL( 
       
  1692     CDesC8Array& aUserAgentHeaders, const TDesC8& aUri )
       
  1693     { 
       
  1694     SVPDEBUG1( "CSVPUtility::AddPPreferredIdentityToUserHeadersL In" )
       
  1695     
       
  1696     TBuf8<KSVPTempStringlength> pPreferredHeaderString;
       
  1697     pPreferredHeaderString.Append( KSVPPIdentity );
       
  1698     pPreferredHeaderString.Append( KSVPLeftBracketMark );
       
  1699     pPreferredHeaderString.Append( aUri );
       
  1700     pPreferredHeaderString.Append( KSVPRightBracketMark );
       
  1701     aUserAgentHeaders.AppendL( pPreferredHeaderString );
       
  1702     
       
  1703     SVPDEBUG1( "CSVPUtility::AddPPreferredIdentityToUserHeadersL Out " )
       
  1704     }
       
  1705 
       
  1706 // ---------------------------------------------------------------------------
       
  1707 // CSVPUtility::GetTerminalTypeL
       
  1708 // ---------------------------------------------------------------------------
       
  1709 //
       
  1710 void CSVPUtility::GetTerminalTypeL(
       
  1711 	    TBuf< KSVPMaxTerminalTypeLength >& aTerminalType )
       
  1712     {
       
  1713     // Using ipapputils functionality
       
  1714     TBuf<KSVPMaxTerminalTypeLength> terminalType (KNullDesC);
       
  1715     
       
  1716     CIpAppPhoneUtils* libIpAppPhoneUtils = CIpAppPhoneUtils::NewLC();
       
  1717     
       
  1718     libIpAppPhoneUtils->GetTerminalTypeL( terminalType );    
       
  1719 
       
  1720     CleanupStack::PopAndDestroy( libIpAppPhoneUtils );
       
  1721     aTerminalType.Copy( terminalType );    
       
  1722     }
       
  1723 
       
  1724 // ---------------------------------------------------------------------------
       
  1725 // CSVPUtility::GetWlanMACAddressL
       
  1726 // ---------------------------------------------------------------------------
       
  1727 //
       
  1728 void CSVPUtility::GetWlanMACAddressL(
       
  1729     TBuf< KSVPWlanMacAddressLength >& aWlanMACAddress ) 
       
  1730     {    
       
  1731     // Using ipapputils functionality
       
  1732     TBuf8<KSVPWlanMacAddressLength> wlanMacAddress (KNullDesC8);
       
  1733     
       
  1734     CIPAppUtilsAddressResolver* addressResolver = 
       
  1735             CIPAppUtilsAddressResolver::NewLC();    
       
  1736     
       
  1737     TInt ret = addressResolver->GetWlanMACAddress( wlanMacAddress, 
       
  1738             KSVPWlanMacAddressFrmt );
       
  1739 		
       
  1740     SVPDEBUG2("CSVPUtility::GetWlanMACAddressL ret: %d", ret );
       
  1741 	
       
  1742     CleanupStack::PopAndDestroy( addressResolver );
       
  1743     aWlanMACAddress.Copy( wlanMacAddress );
       
  1744     }
       
  1745 
       
  1746 // ---------------------------------------------------------------------------
       
  1747 // CSVPUtility::ResolveSecurityMechanismL
       
  1748 // ---------------------------------------------------------------------------
       
  1749 //
       
  1750 void CSVPUtility::ResolveSecurityMechanismL( const CSIPProfile& aProfile,
       
  1751                                              TUint32& aSecureCallPreference )
       
  1752     {
       
  1753     const TDesC8* securityMechanism = NULL;
       
  1754     const TDesC8* sipUserAor = NULL;
       
  1755     const TDesC8* sipOutboundProxy = NULL;
       
  1756     const TDesC8* registeredContact = NULL;
       
  1757 
       
  1758     aProfile.GetParameter( KSIPNegotiatedSecurityMechanism,
       
  1759                             securityMechanism );
       
  1760     aProfile.GetParameter( KSIPUserAor,
       
  1761                             sipUserAor );
       
  1762     aProfile.GetParameter( KSIPOutboundProxy,
       
  1763                             KSIPServerAddress,
       
  1764                             sipOutboundProxy );
       
  1765     aProfile.GetParameter( KSIPRegisteredContact,
       
  1766                             KSIPServerAddress,
       
  1767                             registeredContact );
       
  1768 
       
  1769     if ( KErrNotFound == securityMechanism->Find( KSVPTLS ) &&
       
  1770          KErrNotFound == sipUserAor->Find( KSVPSipsPrefix ) &&
       
  1771          KErrNotFound == sipOutboundProxy->Find( KSVPSipsPrefix ) &&
       
  1772          KErrNotFound == registeredContact->Find( KSVPSipsPrefix ) )
       
  1773         {
       
  1774         SVPDEBUG1("CSVPUtility::ResolveSecurityMechanism:\
       
  1775          TLS not enabled (tls and sips: wasn't found)");
       
  1776         aSecureCallPreference = 0;
       
  1777         }
       
  1778     }
       
  1779 
       
  1780 // ---------------------------------------------------------------------------
       
  1781 // CSVPUtility::MatchLanguageTags
       
  1782 // ---------------------------------------------------------------------------
       
  1783 //
       
  1784 void CSVPUtility::MatchLanguageTags( TInt aLanguageCode, 
       
  1785     TDes& aLangMatch )
       
  1786     {
       
  1787     SVPDEBUG2("CSVPUtility::MatchLanguageTags Langcode: %d", aLanguageCode );
       
  1788     
       
  1789     switch( aLanguageCode)
       
  1790         {
       
  1791         case ESVPLangEnglish:
       
  1792             {
       
  1793             SVPDEBUG1("CSVPUtility::MatchLanguageTags -> English");
       
  1794             aLangMatch.Copy( KSVPLanguageTagEn );
       
  1795             break;
       
  1796             }  
       
  1797         case ESVPLangFrench:
       
  1798             {
       
  1799             aLangMatch.Copy( KSVPLanguageTagFr );
       
  1800             break;
       
  1801             }      
       
  1802         case ESVPLangGerman:
       
  1803             {
       
  1804             aLangMatch.Copy( KSVPLanguageTagDe );
       
  1805             break;
       
  1806             }       
       
  1807         case ESVPLangSpanish:
       
  1808             {
       
  1809             aLangMatch.Copy( KSVPLanguageTagEs );
       
  1810             break;
       
  1811             }      
       
  1812         case ESVPLangItalian:
       
  1813             {
       
  1814             aLangMatch.Copy( KSVPLanguageTagIt );
       
  1815             break;
       
  1816             } 
       
  1817         case ESVPLangSwedish:
       
  1818             {
       
  1819             aLangMatch.Copy( KSVPLanguageTagSv );
       
  1820             break;
       
  1821             } 
       
  1822         case ESVPLangDanish:
       
  1823             {
       
  1824             aLangMatch.Copy( KSVPLanguageTagDa );
       
  1825             break;
       
  1826             }                      
       
  1827         case ESVPLangNorwegian: 
       
  1828             {
       
  1829             aLangMatch.Copy( KSVPLanguageTagNo );
       
  1830             break;
       
  1831             }
       
  1832         case ESVPLangFinnish: 
       
  1833             {
       
  1834             aLangMatch.Copy( KSVPLanguageTagFi );
       
  1835             break;
       
  1836             }
       
  1837         case ESVPLangAmerican:
       
  1838             {
       
  1839             aLangMatch.Copy( KSVPLanguageTagEn );
       
  1840             break;
       
  1841             }
       
  1842         case ESVPLangSwissFrench: 
       
  1843             {
       
  1844             aLangMatch.Copy( KSVPLanguageTagFr );
       
  1845             break;
       
  1846             }
       
  1847         case ESVPLangSwissGerman:
       
  1848             {
       
  1849             aLangMatch.Copy( KSVPLanguageTagDe );
       
  1850             break;
       
  1851             }
       
  1852         case ESVPLangPortuguese:
       
  1853             {
       
  1854             aLangMatch.Copy( KSVPLanguageTagPt );
       
  1855             break;
       
  1856             }
       
  1857         case ESVPLangTurkish: 
       
  1858             {
       
  1859             aLangMatch.Copy( KSVPLanguageTagTr );
       
  1860             break;
       
  1861             }
       
  1862         case ESVPLangIcelandic:
       
  1863             {
       
  1864             aLangMatch.Copy( KSVPLanguageTagIs );
       
  1865             break;
       
  1866             } 
       
  1867         case ESVPLangRussian:
       
  1868             {
       
  1869             aLangMatch.Copy( KSVPLanguageTagRu );
       
  1870             break;
       
  1871             }
       
  1872         case ESVPLangHungarian:
       
  1873             {
       
  1874             aLangMatch.Copy( KSVPLanguageTagHu );
       
  1875             break;
       
  1876             }
       
  1877         case ESVPLangDutch:
       
  1878             {
       
  1879             aLangMatch.Copy( KSVPLanguageTagNl );
       
  1880             break;
       
  1881             }
       
  1882         case ESVPLangBelgianFlemish:
       
  1883             {
       
  1884             aLangMatch.Copy( KSVPLanguageTagNl );
       
  1885             break;
       
  1886             }
       
  1887         case ESVPLangAustralian:
       
  1888             {
       
  1889             aLangMatch.Copy( KSVPLanguageTagEn );
       
  1890             break;
       
  1891             }
       
  1892         case ESVPLangBelgianFrench:
       
  1893             {
       
  1894             aLangMatch.Copy( KSVPLanguageTagFr );
       
  1895             break;
       
  1896             }
       
  1897         case ESVPLangAustrian:
       
  1898             {
       
  1899             aLangMatch.Copy( KSVPLanguageTagDe );
       
  1900             break;
       
  1901             }
       
  1902         case ESVPLangNewZealand:
       
  1903             {
       
  1904             aLangMatch.Copy( KSVPLanguageTagEn );
       
  1905             break;
       
  1906             }
       
  1907         case ESVPLangInternationalFrench:
       
  1908             {
       
  1909             aLangMatch.Copy( KSVPLanguageTagFr );
       
  1910             break;
       
  1911             }
       
  1912         case ESVPLangCzech:
       
  1913             {
       
  1914             aLangMatch.Copy( KSVPLanguageTagCs );
       
  1915             break;
       
  1916             }
       
  1917         case ESVPLangSlovak:
       
  1918             {
       
  1919             aLangMatch.Copy( KSVPLanguageTagSk );
       
  1920             break;
       
  1921             }
       
  1922         case ESVPLangPolish:
       
  1923             {
       
  1924             aLangMatch.Copy( KSVPLanguageTagPl );
       
  1925             break;
       
  1926             }
       
  1927         case ESVPLangSlovenian:
       
  1928             {
       
  1929             aLangMatch.Copy( KSVPLanguageTagSl );
       
  1930             break;
       
  1931             }
       
  1932         case ESVPLangTaiwanChinese:
       
  1933             {
       
  1934             aLangMatch.Copy( KSVPLanguageTagTaiwaneseChinese );
       
  1935             break;
       
  1936             }
       
  1937         case ESVPLangHongKongChinese:
       
  1938             {
       
  1939             aLangMatch.Copy( KSVPLanguageTagHongKongChinese );
       
  1940             break;
       
  1941             }
       
  1942         case ESVPLangPrcChinese:
       
  1943             {
       
  1944             aLangMatch.Copy( KSVPLanguageTagChinese );
       
  1945             break;
       
  1946             }
       
  1947         case ESVPLangJapanese:
       
  1948             {
       
  1949             aLangMatch.Copy( KSVPLanguageTagJa );
       
  1950             break;
       
  1951             }
       
  1952         case ESVPLangThai:
       
  1953             {
       
  1954             aLangMatch.Copy( KSVPLanguageTagTh );
       
  1955             break;
       
  1956             }
       
  1957         case ESVPLangAfrikaans:
       
  1958             {
       
  1959             aLangMatch.Copy( KSVPLanguageTagAf );
       
  1960             break;
       
  1961             }
       
  1962         case ESVPLangAlbanian:
       
  1963             {
       
  1964             aLangMatch.Copy( KSVPLanguageTagSq );
       
  1965             break;
       
  1966             }
       
  1967         case ESVPLangAmharic:
       
  1968             {
       
  1969             aLangMatch.Copy( KSVPLanguageTagAm );
       
  1970             break;
       
  1971             }
       
  1972         case ESVPLangArabic:
       
  1973             {
       
  1974             aLangMatch.Copy( KSVPLanguageTagAr );
       
  1975             break;
       
  1976             }
       
  1977         case ESVPLangArmenian:
       
  1978             {
       
  1979             aLangMatch.Copy( KSVPLanguageTagHy );
       
  1980             break;
       
  1981             }
       
  1982         case ESVPLangTagalog:
       
  1983             {
       
  1984             aLangMatch.Copy( KSVPLanguageTagTl );
       
  1985             break;
       
  1986             }
       
  1987         case ESVPLangBelarussian:
       
  1988             {
       
  1989             aLangMatch.Copy( KSVPLanguageTagBe );
       
  1990             break;
       
  1991             }
       
  1992         case ESVPLangBengali:
       
  1993             {
       
  1994             aLangMatch.Copy( KSVPLanguageTagBn );
       
  1995             break;
       
  1996             }
       
  1997         case ESVPLangBulgarian:
       
  1998             {
       
  1999             aLangMatch.Copy( KSVPLanguageTagBg );
       
  2000             break;
       
  2001             }
       
  2002         case ESVPLangBurmese:
       
  2003             {
       
  2004             aLangMatch.Copy( KSVPLanguageTagMy );
       
  2005             break;
       
  2006             }
       
  2007         case ESVPLangCatalan:
       
  2008             {
       
  2009             aLangMatch.Copy( KSVPLanguageTagCa );
       
  2010             break;
       
  2011             }
       
  2012         case ESVPLangCroatian:
       
  2013             {
       
  2014             aLangMatch.Copy( KSVPLanguageTagHr );
       
  2015             break;
       
  2016             }
       
  2017         case ESVPLangCanadianEnglish:
       
  2018         case ESVPLangInternationalEnglish:
       
  2019         case ESVPLangSouthAfricanEnglish:
       
  2020             {
       
  2021             aLangMatch.Copy( KSVPLanguageTagEn );
       
  2022             break;
       
  2023             }
       
  2024         case ESVPLangEstonian:
       
  2025             {
       
  2026             aLangMatch.Copy( KSVPLanguageTagEt );
       
  2027             break;
       
  2028             }
       
  2029         case ESVPLangFarsi:
       
  2030             {
       
  2031             aLangMatch.Copy( KSVPLanguageTagFa );
       
  2032             break;
       
  2033             }
       
  2034         case ESVPLangCanadianFrench:
       
  2035             {
       
  2036             aLangMatch.Copy( KSVPLanguageTagCanadianFrench );
       
  2037             break;
       
  2038             }
       
  2039         case ESVPLangScotsGaelic:
       
  2040             {
       
  2041             aLangMatch.Copy( KSVPLanguageTagGd );
       
  2042             break;
       
  2043             }
       
  2044         case ESVPLangGeorgian:
       
  2045             {
       
  2046             aLangMatch.Copy( KSVPLanguageTagKa );
       
  2047             break;
       
  2048             }
       
  2049         case ESVPLangGreek:
       
  2050             {
       
  2051             aLangMatch.Copy( KSVPLanguageTagEl );
       
  2052             break;
       
  2053             }
       
  2054         case ESVPLangCyprusGreek:
       
  2055             {
       
  2056             aLangMatch.Copy( KSVPLanguageTagCyprusGreek );
       
  2057             break;
       
  2058             }
       
  2059         case ESVPLangGujarati:
       
  2060             {
       
  2061             aLangMatch.Copy( KSVPLanguageTagGu );
       
  2062             break;
       
  2063             }
       
  2064         case ESVPLangHebrew:
       
  2065             {
       
  2066             aLangMatch.Copy( KSVPLanguageTagHe );
       
  2067             break;
       
  2068             }
       
  2069         case ESVPLangHindi:
       
  2070             {
       
  2071             aLangMatch.Copy( KSVPLanguageTagHi );
       
  2072             break;
       
  2073             }
       
  2074         case ESVPLangIndonesian:
       
  2075             {
       
  2076             aLangMatch.Copy( KSVPLanguageTagId );
       
  2077             break;
       
  2078             }
       
  2079         case ESVPLangIrish:
       
  2080             {
       
  2081             aLangMatch.Copy( KSVPLanguageTagGa );
       
  2082             break;
       
  2083             }
       
  2084         case ESVPLangSwissItalian:
       
  2085             {
       
  2086             aLangMatch.Copy( KSVPLanguageTagSwissItalian );
       
  2087             break;
       
  2088             }
       
  2089         case ESVPLangKannada:
       
  2090             {
       
  2091             aLangMatch.Copy( KSVPLanguageTagKn );
       
  2092             break;
       
  2093             }
       
  2094         case ESVPLangKazakh:
       
  2095             {
       
  2096             aLangMatch.Copy( KSVPLanguageTagKk );
       
  2097             break;
       
  2098             }
       
  2099         case ESVPLangKhmer:
       
  2100             {
       
  2101             aLangMatch.Copy( KSVPLanguageTagKm );
       
  2102             break;
       
  2103             }
       
  2104         case ESVPLangKorean:
       
  2105             {
       
  2106             aLangMatch.Copy( KSVPLanguageTagKo );
       
  2107             break;
       
  2108             }
       
  2109         case ESVPLangLao:
       
  2110             {
       
  2111             aLangMatch.Copy( KSVPLanguageTagLo );
       
  2112             break;
       
  2113             }
       
  2114         case ESVPLangLatvian:
       
  2115             {
       
  2116             aLangMatch.Copy( KSVPLanguageTagLv );
       
  2117             break;
       
  2118             }
       
  2119         case ESVPLangLithuanian:
       
  2120             {
       
  2121             aLangMatch.Copy( KSVPLanguageTagLt );
       
  2122             break;
       
  2123             }
       
  2124         case ESVPLangMacedonian:
       
  2125             {
       
  2126             aLangMatch.Copy( KSVPLanguageTagMk );
       
  2127             break;
       
  2128             }
       
  2129         case ESVPLangMalay:
       
  2130             {
       
  2131             aLangMatch.Copy( KSVPLanguageTagMs );
       
  2132             break;
       
  2133             }
       
  2134         case ESVPLangMalayalam:
       
  2135             {
       
  2136             aLangMatch.Copy( KSVPLanguageTagMl );
       
  2137             break;
       
  2138             }
       
  2139         case ESVPLangMarathi:
       
  2140             {
       
  2141             aLangMatch.Copy( KSVPLanguageTagMr );
       
  2142             break;
       
  2143             }
       
  2144         case ESVPLangMoldavian:
       
  2145             {
       
  2146             aLangMatch.Copy( KSVPLanguageTagMo );
       
  2147             break;
       
  2148             }
       
  2149         case ESVPLangMongolian:
       
  2150             {
       
  2151             aLangMatch.Copy( KSVPLanguageTagMn );
       
  2152             break;
       
  2153             }
       
  2154         case ESVPLangNorwegianNynorsk:
       
  2155             {
       
  2156             aLangMatch.Copy( KSVPLanguageTagNorwegianNynorsk );
       
  2157             break;
       
  2158             }
       
  2159         case ESVPLangBrazilianPortuguese:
       
  2160             {
       
  2161             aLangMatch.Copy( KSVPLanguageTagBrazilianPortugese );
       
  2162             break;
       
  2163             }
       
  2164         case ESVPLangPunjabi:
       
  2165             {
       
  2166             aLangMatch.Copy( KSVPLanguageTagPa );
       
  2167             break;
       
  2168             }
       
  2169         case ESVPLangRomanian:
       
  2170             {
       
  2171             aLangMatch.Copy( KSVPLanguageTagRo );
       
  2172             break;
       
  2173             }
       
  2174         case ESVPLangSerbian:
       
  2175             {
       
  2176             aLangMatch.Copy( KSVPLanguageTagSr );
       
  2177             break;
       
  2178             }
       
  2179         case ESVPLangSinhalese:
       
  2180             {
       
  2181             aLangMatch.Copy( KSVPLanguageTagSi );
       
  2182             break;
       
  2183             }
       
  2184         case ESVPLangSomali:
       
  2185             {
       
  2186             aLangMatch.Copy( KSVPLanguageTagSo );
       
  2187             break;
       
  2188             }
       
  2189         case ESVPLangInternationalSpanish:
       
  2190             {
       
  2191             aLangMatch.Copy( KSVPLanguageTagEs );
       
  2192             break;
       
  2193             }
       
  2194         case ESVPLangLatinAmericanSpanish:
       
  2195             {
       
  2196             aLangMatch.Copy( KSVPLanguageTagAmericanSpanish );
       
  2197             break;
       
  2198             }
       
  2199         case ESVPLangSwahili:
       
  2200             {
       
  2201             aLangMatch.Copy( KSVPLanguageTagSw );
       
  2202             break;
       
  2203             }
       
  2204         case ESVPLangFinlandSwedish:
       
  2205             {
       
  2206             aLangMatch.Copy( KSVPLanguageTagFinlandSwedish );
       
  2207             break;
       
  2208             }
       
  2209         case ESVPLangReserved1:
       
  2210             {
       
  2211             aLangMatch.Copy( KSVPLanguageTagReserved );
       
  2212             break;
       
  2213             }
       
  2214         case ESVPLangTamil:
       
  2215             {
       
  2216             aLangMatch.Copy( KSVPLanguageTagTa );
       
  2217             break;
       
  2218             }
       
  2219         case ESVPLangTelugu:
       
  2220             {
       
  2221             aLangMatch.Copy( KSVPLanguageTagTe );
       
  2222             break;
       
  2223             }
       
  2224         case ESVPLangTibetan:
       
  2225             {
       
  2226             aLangMatch.Copy( KSVPLanguageTagBo );
       
  2227             break;
       
  2228             }
       
  2229         case ESVPLangTigrinya:
       
  2230             {
       
  2231             aLangMatch.Copy( KSVPLanguageTagTi );
       
  2232             break;
       
  2233             }
       
  2234         case ESVPLangCyprusTurkish:
       
  2235             {
       
  2236             aLangMatch.Copy( KSVPLanguageTagCyprusTurkish );
       
  2237             break;
       
  2238             }
       
  2239         case ESVPLangTurkmen:
       
  2240             {
       
  2241             aLangMatch.Copy( KSVPLanguageTagTurkaem );
       
  2242             break;
       
  2243             }
       
  2244         case ESVPLangUkrainian:
       
  2245             {
       
  2246             aLangMatch.Copy( KSVPLanguageTagUk );
       
  2247             break;
       
  2248             }
       
  2249         case ESVPLangUrdu:
       
  2250             {
       
  2251             aLangMatch.Copy( KSVPLanguageTagUr );
       
  2252             break;
       
  2253             }
       
  2254         case ESVPLangReserved2:
       
  2255             {
       
  2256             aLangMatch.Copy( KSVPLanguageTagReserved );
       
  2257             break;
       
  2258             }
       
  2259         case ESVPLangVietnamese:
       
  2260             {
       
  2261             aLangMatch.Copy( KSVPLanguageTagVi );
       
  2262             break;
       
  2263             }
       
  2264         
       
  2265         case ESVPLangWelsh:
       
  2266             {
       
  2267             aLangMatch.Copy( KSVPLanguageTagCy );
       
  2268             break;
       
  2269             }
       
  2270         case ESVPLangZulu:
       
  2271             {
       
  2272             aLangMatch.Copy( KSVPLanguageTagZu );
       
  2273             break;
       
  2274             }
       
  2275         case ESVPLangOther:
       
  2276             {
       
  2277             break;
       
  2278             }
       
  2279         case ESVPLangSouthSotho:
       
  2280             {
       
  2281             aLangMatch.Copy( KSVPLanguageTagSoth );
       
  2282             break;
       
  2283             }
       
  2284         case ESVPLangManufacturerEnglish:
       
  2285         case ESVPLangEnglish_Apac:
       
  2286         case ESVPLangEnglish_Taiwan:
       
  2287         case ESVPLangEnglish_HongKong:
       
  2288         case ESVPLangEnglish_Prc:
       
  2289         case ESVPLangEnglish_Japan:
       
  2290         case ESVPLangEnglish_Thailand:
       
  2291             {
       
  2292             aLangMatch.Copy( KSVPLanguageTagEn );
       
  2293             break;
       
  2294             }
       
  2295         case ESVPLangMalay_Apac:
       
  2296             {
       
  2297             aLangMatch.Copy( KSVPLanguageTagMalay );
       
  2298             break;
       
  2299             }
       
  2300         case ESVPLangNone:
       
  2301         case ESVPLangMaximum:
       
  2302             {
       
  2303             SVPDEBUG1("CSVPUtility::MatchLanguageTags Lang none/maximum");
       
  2304             break;
       
  2305             } 
       
  2306         default:
       
  2307             {
       
  2308             SVPDEBUG1("CSVPUtility::MatchLanguageTags Default");
       
  2309             aLangMatch.Copy( KSVPLanguageTagEn );
       
  2310             }
       
  2311         }
       
  2312     }
       
  2313 
       
  2314 // ---------------------------------------------------------------------------
       
  2315 // CSVPUtility::UpdateJitterBufferSizeL
       
  2316 // ---------------------------------------------------------------------------
       
  2317 //
       
  2318 void CSVPUtility::UpdateJitterBufferSizeL( CMceRtpSource& aRtpSource )
       
  2319     {
       
  2320     // Convert the jitterbuffer size from milliseconds to RTP packets. This
       
  2321     // does not take into account the fact that RTP packet can hold n
       
  2322     // milliseconds of audio. Also G.711 may use 10ms frames, so and we are
       
  2323     // assuming 20ms frames here. But, MCC actually has the logic to handle
       
  2324     // this issue, as it also assumes initially that G.711 has 20ms frames and
       
  2325     // then adjusts accordingly.
       
  2326     TInt32 jBufSize = KSvpJitterBufferLength;
       
  2327     if ( iJitterBufferSize )
       
  2328         {
       
  2329         jBufSize = iJitterBufferSize / KJitterBufferFrameSize;
       
  2330         }
       
  2331     
       
  2332     SVPDEBUG2( "CSVPUtility::UpdateJitterBufferSizeL size: %d", jBufSize );
       
  2333     SVPDEBUG2( "CSVPUtility::UpdateJitterBufferSizeL iJitterBufferSize: %d",
       
  2334         iJitterBufferSize );
       
  2335     
       
  2336     // If jitterbuffer size goes to zero, then force it back to default. We
       
  2337     // cannot tolerate zero size jitterbuffer.
       
  2338     if ( !jBufSize )
       
  2339         {
       
  2340         SVPDEBUG1( "CSVPUtility::UpdateJitterBufferSizeL need to default" )
       
  2341         
       
  2342         jBufSize = KSvpJitterBufferLength;
       
  2343         }
       
  2344     
       
  2345     aRtpSource.UpdateL( jBufSize, 
       
  2346                         KSvpJitterBufferThreshold,
       
  2347                         KSvpStandbyTimerInMillisecs );
       
  2348                         
       
  2349     iJitterBufferSize = 0;
       
  2350     }
       
  2351 
       
  2352 // ---------------------------------------------------------------------------
       
  2353 // CSVPUtility::SetDtmfCodecOrderL
       
  2354 // ---------------------------------------------------------------------------
       
  2355 //
       
  2356 void CSVPUtility::SetDtmfCodecOrderL( CMceAudioStream& aAudioStream ) const
       
  2357     {
       
  2358     SVPDEBUG1( "CSVPUtility::SetDtmfCodecOrderL In" );
       
  2359  
       
  2360     const RPointerArray<CMceAudioCodec>& codecs = aAudioStream.Codecs();
       
  2361     const TInt codCount( codecs.Count() );
       
  2362      
       
  2363     // loop through codecs in in stream
       
  2364     for ( TInt i = 0; i < codCount; i++ )
       
  2365         {
       
  2366         // Check if codec is DTMF, note the return values of CompareF
       
  2367         if( !codecs[ i ]->SdpName().CompareF( KTELEVENT ) )
       
  2368             {
       
  2369             codecs[ i ]->SetPreferenceL( iPreferredCodec );
       
  2370             }
       
  2371         }
       
  2372     SVPDEBUG1( "CSVPUtility::SetDtmfCodecOrderL Out" );
       
  2373     }
       
  2374 
       
  2375 // ---------------------------------------------------------------------------
       
  2376 // CSVPUtility::SetMediaQoSL
       
  2377 // ---------------------------------------------------------------------------
       
  2378 //
       
  2379 void CSVPUtility::SetMediaQoSL( TUint32 aQosValue,
       
  2380     CMceSession* aSession ) const
       
  2381     {
       
  2382     SVPDEBUG2( "CSVPUtility::SetMediaQoSL aQosValue: %u", aQosValue );
       
  2383     
       
  2384     __ASSERT_ALWAYS( aSession, User::Leave( KErrArgument ) );
       
  2385     
       
  2386     // We need to do bitshifting on the IP TOS, because it's the upper 6 bits
       
  2387     // that are set and settings provide us the IP TOS as the lower 6 bits.
       
  2388     // The lower 2 bits are reserver for explicit congestion notification.
       
  2389     // See also more from:
       
  2390     // Symbian Developer Library / in_sock.h Global variables / KSoIpTOS
       
  2391     const TInt ipTosShift( 2 );
       
  2392     const TUint32 tosBits( aQosValue << ipTosShift );
       
  2393     
       
  2394     SVPDEBUG2( "CSVPUtility::SetMediaQoSL tosBits: %u", tosBits );
       
  2395     
       
  2396     aSession->SetServiceTypeL( tosBits );
       
  2397     
       
  2398     SVPDEBUG1( "CSVPUtility::SetMediaQoSL out" );
       
  2399     }
       
  2400 
       
  2401 // ---------------------------------------------------------------------------
       
  2402 // CSVPUtility::GetKeepAliveByIapIdL
       
  2403 // ---------------------------------------------------------------------------
       
  2404 //
       
  2405 TBool CSVPUtility::GetKeepAliveByIapIdL( TUint32 aIapId,
       
  2406     TInt& aKeepAliveValue ) const
       
  2407     {
       
  2408     SVPDEBUG2( "CSVPUtility::SetKeepAliveIapIdL IN, aIapId = %d", aIapId );
       
  2409 
       
  2410     TBool found = EFalse;
       
  2411     TInt keepAliveValue = 0;
       
  2412     aKeepAliveValue = KSVPDefaultUDPRefreshInterval;
       
  2413     RArray< TUint32 > keys;
       
  2414     CleanupClosePushL( keys );
       
  2415 
       
  2416     CRepository* rep = CRepository::NewLC( KCRUidUNSAFProtocols );
       
  2417 
       
  2418     TInt err = rep->FindEqL( KUNSAFProtocolsIAPIdMask,
       
  2419                              KUNSAFProtocolsFieldTypeMask,
       
  2420                              static_cast<TInt>(aIapId),
       
  2421                              keys );
       
  2422 
       
  2423     if ( KErrNone == err  && keys.Count() == 1 )
       
  2424         {
       
  2425 
       
  2426         TUint32 key = ( KUNSAFProtocolsIAPIdMask^( keys[ 0 ] ) );
       
  2427         key |= KUNSAFProtocolsIAPTableMask;
       
  2428 
       
  2429         // UDP refresh interval
       
  2430         SVPDEBUG2( "CSVPUtility::SetKeepAliveIapIdL UDP refresh interval key = %d", key );
       
  2431         if ( KErrNone == rep->Get( KUNSAFProtocolsIntervalUDPMask|key, keepAliveValue ) )
       
  2432             {
       
  2433             aKeepAliveValue = keepAliveValue;
       
  2434             found = ETrue;
       
  2435             }
       
  2436         }
       
  2437 
       
  2438     CleanupStack::PopAndDestroy( 2, &keys );  // keys & rep
       
  2439     SVPDEBUG3( "CSVPUtility::SetKeepAliveIapIdL OUT keepAliveValue = %d found = %d",
       
  2440                     keepAliveValue, found );
       
  2441     return found;
       
  2442     }
       
  2443 
       
  2444 // ---------------------------------------------------------------------------
       
  2445 // CSVPUtility::GetKeepAliveByAORL
       
  2446 // ---------------------------------------------------------------------------
       
  2447 //
       
  2448 TBool CSVPUtility::GetKeepAliveByAORL( const TDesC8& aAor,
       
  2449     TInt& aKeepAliveValue ) const
       
  2450     {
       
  2451     SVPDEBUG1( "CSVPUtility::GetKeepAliveByAORL In" );
       
  2452 
       
  2453     HBufC8* newAor = aAor.AllocLC();
       
  2454     // Domain name is what is after @ character
       
  2455     newAor->Des().Delete( 0, newAor->Find( KSVPAt ) + 1 );
       
  2456 
       
  2457     TBool found = EFalse;
       
  2458     TInt keepAliveValue = 0;
       
  2459     aKeepAliveValue = KSVPDefaultUDPRefreshInterval;
       
  2460     RArray<TUint32> keys;
       
  2461     CleanupClosePushL( keys );
       
  2462 
       
  2463     CRepository* rep = CRepository::NewLC( KCRUidUNSAFProtocols );
       
  2464 
       
  2465     TInt err = rep->FindEqL( KUNSAFProtocolsDomainMask,
       
  2466                              KUNSAFProtocolsFieldTypeMask,
       
  2467                              *newAor,
       
  2468                              keys );
       
  2469 
       
  2470     if ( KErrNone == err && keys.Count() == 1 )
       
  2471         {
       
  2472         TUint32 key = ( KUNSAFProtocolsDomainMask^( keys[0] ) );
       
  2473         key |= KUNSAFProtocolsDomainTableMask;
       
  2474 
       
  2475         // UDP refresh interval
       
  2476         if ( KErrNone ==
       
  2477              rep->Get( KUNSAFProtocolsDomainIntervalUDPMask|key, keepAliveValue ) )
       
  2478             {
       
  2479             aKeepAliveValue = keepAliveValue;
       
  2480             found = ETrue;
       
  2481             }
       
  2482         }
       
  2483 
       
  2484     CleanupStack::PopAndDestroy( 3, newAor );
       
  2485 
       
  2486     if ( !found )
       
  2487         {
       
  2488         // Neither IapId nor Domain spesific keepalive value was not found.
       
  2489         SVPDEBUG1( "CSVPUtility::GetKeepAliveByAORL::GetKeepAliveByAORL use default keepalive" );
       
  2490         
       
  2491         aKeepAliveValue = KSVPDefaultUDPRefreshInterval;
       
  2492         }
       
  2493     
       
  2494     SVPDEBUG2( "CSVPUtility::GetKeepAliveByAORL Out found: %d", found );
       
  2495     return found;
       
  2496     }
       
  2497 
       
  2498 // ---------------------------------------------------------------------------
       
  2499 // CSVPUtility::CheckRtcpSettingL
       
  2500 // ---------------------------------------------------------------------------
       
  2501 //
       
  2502 void CSVPUtility::CheckRtcpSettingL( TUint32 aRtcp,
       
  2503     CMceMediaStream& aStream, TBool aSessionUpdateOngoing ) const
       
  2504     {
       
  2505     SVPDEBUG2( "CSVPUtility::CheckRtcpSettingL aRtcp: %u", aRtcp );
       
  2506     
       
  2507     TBool rtcpsuppression = ETrue;
       
  2508     if ( CRCSEProfileEntry::EOn == aRtcp )
       
  2509         {
       
  2510         SVPDEBUG1("CSVPUtility::CheckRtcpSettingL RTCP=ON");
       
  2511         rtcpsuppression = EFalse;
       
  2512         }
       
  2513     
       
  2514     // At this point we should have only audio streams. Thus the leave.
       
  2515     if ( KMceAudio == aStream.Type() )
       
  2516         {
       
  2517         if ( !aStream.Source()->IsEnabled() && aSessionUpdateOngoing )
       
  2518             {
       
  2519             aStream.Source()->EnableL();
       
  2520             }
       
  2521 
       
  2522         const RPointerArray<CMceMediaSink>& sinks = aStream.Sinks();
       
  2523         const TInt snkCount = sinks.Count();
       
  2524         for ( TInt k = 0; k < snkCount; k++ )
       
  2525             {
       
  2526 
       
  2527             if ( !sinks[k]->IsEnabled()&& aSessionUpdateOngoing )
       
  2528                 {
       
  2529                 sinks[k]->EnableL();
       
  2530                 }
       
  2531 
       
  2532             if ( KMceRTPSink == sinks[k]->Type() )
       
  2533                 {
       
  2534                 SVPDEBUG2( "CSVPUtility::CheckRtcpSettingL updating: %d", k );
       
  2535                 static_cast<CMceRtpSink*>(
       
  2536                     sinks[k] )->UpdateL( rtcpsuppression );
       
  2537                 SVPDEBUG1( "CSspUtility::CheckRtcpSettingL update done" );
       
  2538                 }
       
  2539             }
       
  2540         }
       
  2541     else
       
  2542         {
       
  2543         SVPDEBUG1( "CSspUtility::CheckRtcpSettingL KErrArgument" );
       
  2544         User::Leave( KErrArgument );
       
  2545         }
       
  2546     
       
  2547     SVPDEBUG1( "CSspUtility::CheckRtcpSettingL Exit" );
       
  2548     }
       
  2549 
       
  2550 // ---------------------------------------------------------------------------
       
  2551 // CSVPUtility::SetVADL
       
  2552 // ---------------------------------------------------------------------------
       
  2553 //
       
  2554 void CSVPUtility::SetVADL( CMceAudioStream& aInAudioStream,
       
  2555                            TBool aVADSetting,
       
  2556                            const TDesC8& aCodecName )
       
  2557     {
       
  2558     SVPDEBUG1( "CSVPUtility::SetVADL In" )
       
  2559 
       
  2560     __ASSERT_ALWAYS( &aCodecName, User::Leave( KErrArgument ) );
       
  2561 
       
  2562     if ( &aInAudioStream )
       
  2563         {
       
  2564         CMceAudioCodec* codec = SVPAudioUtility::FindCodec( aInAudioStream, aCodecName );
       
  2565         if ( codec )
       
  2566             {
       
  2567             SVPDEBUG2( "CSVPUtility aInAudioStream and codec valid, setting VAD with %d", aVADSetting )
       
  2568             codec->EnableVAD( aVADSetting );
       
  2569             }
       
  2570         }
       
  2571 
       
  2572     SVPDEBUG1( "CSVPUtility::SetVADL Out" )
       
  2573     }
       
  2574 
       
  2575 // ---------------------------------------------------------------------------
       
  2576 // CSVPUtility::SetAmrWbParameters
       
  2577 // ---------------------------------------------------------------------------
       
  2578 //
       
  2579 void CSVPUtility::SetAmrWbParameters( CMceAudioStream& aAudioInStream, 
       
  2580                                     const CRCSEAudioCodecEntry& aCodecProfile,
       
  2581                                     TInt aCodecNumber )
       
  2582     {
       
  2583     SVPDEBUG1( "CSVPUtility::SetAmrWbParameters In" )
       
  2584     
       
  2585     TUint allowedBitrates( 0 );
       
  2586     
       
  2587     // Set correct mode-set
       
  2588     const RArray< TUint32 >& modeSetArray = aCodecProfile.iModeSet;
       
  2589     for ( TInt i = 0; i < modeSetArray.Count(); i++ )
       
  2590         {
       
  2591         TUint value = modeSetArray[ i ];
       
  2592         switch ( value )
       
  2593             {
       
  2594             case 0: { allowedBitrates |= KMceAllowedAmrWbBitrate660;  break; }
       
  2595             case 1: { allowedBitrates |= KMceAllowedAmrWbBitrate885;  break; }
       
  2596             case 2: { allowedBitrates |= KMceAllowedAmrWbBitrate1265;  break; }
       
  2597             case 3: { allowedBitrates |= KMceAllowedAmrWbBitrate1425;  break; }
       
  2598             case 4: { allowedBitrates |= KMceAllowedAmrWbBitrate1585;  break; }
       
  2599             case 5: { allowedBitrates |= KMceAllowedAmrWbBitrate1825;  break; }
       
  2600             case 6: { allowedBitrates |= KMceAllowedAmrWbBitrate1985;  break; }
       
  2601             case 7: { allowedBitrates |= KMceAllowedAmrWbBitrate2305;  break; }
       
  2602             case 8: { allowedBitrates |= KMceAllowedAmrWbBitrate2305;  break; }
       
  2603             case 9: { allowedBitrates |= KMceAllowedAmrWbBitrate2385;  break; }
       
  2604             default: { allowedBitrates |= KMceAllowedAmrWbBitrateAll;  break; }
       
  2605             }
       
  2606 
       
  2607         SVPDEBUG3( "SetAmrWbParameters round %d, value: %u",
       
  2608             i, value )
       
  2609         SVPDEBUG2( "SetAmrWbParameters allowedBitrates 0x%x",
       
  2610             allowedBitrates )
       
  2611         }
       
  2612 
       
  2613     SVPDEBUG2( "SetAmrWbParameters mode-set 0x%x", allowedBitrates )
       
  2614     
       
  2615     // Set correct mode-change-period (mode-change-period=1):
       
  2616     if ( 2 == aCodecProfile.iModeChangePeriod )
       
  2617         {
       
  2618         allowedBitrates |= KMceAllowedAmrWbModeChangePeriod2;
       
  2619         }
       
  2620 
       
  2621     // Set correct mode-change-neighbor (mode-change-neighbor=0)
       
  2622     if ( CRCSEAudioCodecEntry::EOn == aCodecProfile.iModeChangeNeighbor )
       
  2623         {
       
  2624         allowedBitrates |= KMceAllowedAmrWbModeChangeNeighbor1;
       
  2625         }
       
  2626 
       
  2627     aAudioInStream.Codecs()[ aCodecNumber ]->SetAllowedBitrates(
       
  2628         allowedBitrates );
       
  2629 
       
  2630     SVPDEBUG2( "CSVPUtility::SetAmrWbParameters Out, 0x%x", allowedBitrates )
       
  2631     }
       
  2632 
       
  2633 // EOF