multimediacommsengine/tsrc/mccstub/src/MmccCodecDTMF.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    MCC DTMF CodecInformation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "mmcccodecdtmf.h"
       
    24 #include "mccuids.hrh"
       
    25 #include "mmccinterfacelogs.h"
       
    26 #include "mccinternalcodecs.h"
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 
       
    32 // CONSTANTS
       
    33 const TUint KDefaultSamplingFreq = 8000;
       
    34 const TInt KMaxFmtpAttrLength( 50 );
       
    35 
       
    36 const TText8 KCharComma = ',';
       
    37 const TText8 KCharHyphen = '-';
       
    38 const TText8 KCharSpace = ' ';
       
    39 
       
    40 
       
    41 
       
    42 
       
    43 // MACROS
       
    44 
       
    45 // LOCAL CONSTANTS AND MACROS
       
    46 
       
    47 // MODULE DATA STRUCTURES
       
    48 
       
    49 // LOCAL FUNCTION PROTOTYPES
       
    50 
       
    51 // FORWARD DECLARATIONS
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS ===============================
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS ===============================
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CMccCodecDTMF::CMccCodecDTMF
       
    59 // C++ default constructor can NOT contain any code, that
       
    60 // might leave.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CMccCodecDTMF::CMccCodecDTMF() : CMccCodecInformation()
       
    64     {
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CMccCodecDTMF::ConstructL
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CMccCodecDTMF::ConstructL()
       
    73     {
       
    74     iSdpName.Copy( KTelephoneEvent );
       
    75     
       
    76     iFmtpAttr = HBufC8::NewL( KMaxFmtpAttrLength );
       
    77     SetPTime( KDTMFPTime );
       
    78     SetPayloadType( KDefaultDtmfPT );
       
    79     SetCodecMode( EDTMFModeEvent );
       
    80     SetSamplingFreq( KDefaultSamplingFreq );
       
    81     SetAllowedBitrates( KMccAllowedDtmfNumberALL );
       
    82     iFourCC = KMccFourCCIdDTMF;
       
    83     
       
    84     iPayloadFormatEncoder = KImplUidDTMFPayloadFormatEncode;
       
    85     iPayloadFormatDecoder = KImplUidDTMFPayloadFormatDecode;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CMccCodecDTMF::NewL
       
    90 // Two-phased constructor.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CMccCodecDTMF* CMccCodecDTMF::NewL()
       
    94     {
       
    95     CMccCodecDTMF* self = new( ELeave ) CMccCodecDTMF;
       
    96     
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL();
       
    99     CleanupStack::Pop( self );
       
   100 
       
   101     return self;
       
   102     }
       
   103 
       
   104     
       
   105 // -----------------------------------------------------------------------------
       
   106 // CMccCodecDTMF::~CMccCodecDTMF
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CMccCodecDTMF::~CMccCodecDTMF()
       
   110     {
       
   111     }
       
   112     
       
   113 // -----------------------------------------------------------------------------
       
   114 // CMccCodecDTMF::RequireSignalling
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 TBool CMccCodecDTMF::RequireSignalling(
       
   118     const CMccCodecInformation& aCandidate ) const      
       
   119     {
       
   120     return CMccCodecInformation::RequireSignalling( aCandidate );
       
   121     }
       
   122        
       
   123 // -----------------------------------------------------------------------------
       
   124 // CMccCodecDTMF::SetBitrate
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 TInt CMccCodecDTMF::SetBitrate( TUint aBitrate )
       
   128     {
       
   129     return ( aBitrate > 0 ) ? KErrNotSupported : KErrNone;
       
   130     }
       
   131     
       
   132 // -----------------------------------------------------------------------------
       
   133 // CMccCodecDTMF::SetSamplingFreq
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 TInt CMccCodecDTMF::SetSamplingFreq( TUint32 aSamplingFreq )
       
   137     {
       
   138     return ( KDefaultSamplingFreq != aSamplingFreq ) ? KErrNotSupported : KErrNone;
       
   139     }
       
   140     
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMccCodecDTMF::SetSdpName
       
   143 // Sets the SDP name
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 TInt CMccCodecDTMF::SetSdpName( const TDesC8& aSdpName )
       
   147     {
       
   148     if ( 0 == aSdpName.CompareF( KTelephoneEvent ) )
       
   149         {
       
   150         iSdpName.Copy( aSdpName );
       
   151         }
       
   152     else 
       
   153         {
       
   154         return KErrNotSupported;
       
   155         }
       
   156     
       
   157     return KErrNone;
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CMccCodecDTMF::PayloadType
       
   162 // Sets the payload type
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 TInt CMccCodecDTMF::SetPayloadType( TUint8 aPayloadType )
       
   166     {
       
   167     if ( aPayloadType < KMinDynamicPT ||
       
   168          aPayloadType > KMaxPayloadType ) 
       
   169         {
       
   170         return KErrNotSupported;
       
   171         }
       
   172     else 
       
   173         {
       
   174         iPayloadType = aPayloadType;
       
   175         }
       
   176               
       
   177     return KErrNone;
       
   178     }
       
   179     
       
   180 // -----------------------------------------------------------------------------
       
   181 // CMccCodecDTMF::SetCodecMode
       
   182 // Sets the codec mode.
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 TInt CMccCodecDTMF::SetCodecMode( TCodecMode aCodecMode )
       
   186     {
       
   187 	if ( EDTMFModeEvent == aCodecMode )
       
   188 	    {
       
   189 	    iCodecMode = aCodecMode;
       
   190 	    return KErrNone;
       
   191 	    }
       
   192     else if( EDTMFModeInband == aCodecMode )
       
   193         {
       
   194         iCodecMode = aCodecMode;
       
   195         return KErrNone;
       
   196         }
       
   197     else
       
   198         {
       
   199         return KErrNotSupported;
       
   200         }
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CMccCodecDTMF::SetAllowedBitrates
       
   205 // -----------------------------------------------------------------------------
       
   206 //    
       
   207 TInt CMccCodecDTMF::SetAllowedBitrates( TUint aBitrateMask )
       
   208     {
       
   209     if ( (aBitrateMask >> 16 ) > 0 )
       
   210         {
       
   211         return KErrArgument;
       
   212         }
       
   213     else
       
   214         {
       
   215         iBitrateMask = KMccAllowedDtmfNumberALL;
       
   216         iBitrateMask &= aBitrateMask;
       
   217         }
       
   218     
       
   219     return KErrNone;
       
   220     
       
   221     }
       
   222  
       
   223 // -----------------------------------------------------------------------------
       
   224 // CMccCodecDTMF::EnableVAD
       
   225 // Enable / Disable VAD
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 TInt CMccCodecDTMF::EnableVAD( TBool aEnableVAD ) 
       
   229     {
       
   230     return aEnableVAD ? KErrNotSupported : KErrNone;
       
   231     }
       
   232     
       
   233 // -----------------------------------------------------------------------------
       
   234 // CMccCodecDTMF::SetPTime
       
   235 // Set PTime
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 TInt CMccCodecDTMF::SetPTime( TUint aPTime )
       
   239     {
       
   240     if ( ( aPTime <= 200 ) && (( aPTime % 10 )  == 0 ))
       
   241         {
       
   242         iPTime = aPTime;
       
   243         return KErrNone;    
       
   244         }
       
   245     else
       
   246         {
       
   247         return KErrNotSupported;
       
   248         }
       
   249     }
       
   250     
       
   251 // -----------------------------------------------------------------------------
       
   252 // CMccCodecDTMF::SetMaxPTime
       
   253 // Set Max PTime
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 TInt CMccCodecDTMF::SetMaxPTime( TUint aMaxPTime )
       
   257     {
       
   258     if ( ( aMaxPTime <= 200 ) && (( aMaxPTime % 10 )  == 0 ))
       
   259         {
       
   260         iMaxPTime = aMaxPTime;
       
   261         return KErrNone;    
       
   262         }
       
   263     else
       
   264         {
       
   265         return KErrNotSupported;
       
   266         }
       
   267     }
       
   268     
       
   269 // -----------------------------------------------------------------------------
       
   270 // CMccCodecDTMF::CloneDefaultsL
       
   271 // Make a default setting clone from this DTMF codec
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 CMccCodecInformation* CMccCodecDTMF::CloneDefaultsL()
       
   275     {
       
   276     return CMccCodecDTMF::NewL();
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CMccCodecDTMF::CloneDetailedL
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 CMccCodecInformation* CMccCodecDTMF::CloneDetailedL()
       
   284     {
       
   285     CMccCodecDTMF* newCodec = CMccCodecDTMF::NewL();
       
   286     CleanupStack::PushL( newCodec );
       
   287     newCodec->SetBitrate( this->Bitrate() );
       
   288     newCodec->SetAllowedBitrates( this->AllowedBitrates() );
       
   289     newCodec->SetCodecMode( this->CodecMode() );
       
   290     newCodec->SetMaxPTime( this->MaxPTime() );
       
   291     newCodec->SetPayloadType( this->PayloadType() );
       
   292     newCodec->SetPTime( this->PTime() );
       
   293     newCodec->SetSamplingFreq( this->SamplingFreq() );
       
   294     newCodec->SetSdpName( this->SdpName() );  
       
   295     CleanupStack::Pop( newCodec );
       
   296     return newCodec;
       
   297     }
       
   298     
       
   299 // -----------------------------------------------------------------------------
       
   300 // CMccCodecDTMF::GetFmtpL
       
   301 // -----------------------------------------------------------------------------
       
   302 // 
       
   303 TDesC8& CMccCodecDTMF::GetFmtpL()
       
   304     {
       
   305     __INTERFACE( "CMccCodecDTMF::GetFmtpL" )      
       
   306  
       
   307     delete iFmtpAttr;
       
   308     iFmtpAttr = NULL;
       
   309 
       
   310     CreateFmtpAttrListL();
       
   311     
       
   312     __INTERFACE( "CMccCodecDTMF::GetFmtpL, exit" ) 
       
   313          
       
   314     return *iFmtpAttr;    
       
   315     }
       
   316    
       
   317 // -----------------------------------------------------------------------------
       
   318 // CMccCodecDTMF::CreateFmtpAttrListL
       
   319 // -----------------------------------------------------------------------------
       
   320 //  
       
   321 void CMccCodecDTMF::CreateFmtpAttrListL()
       
   322     {
       
   323     __INTERFACE( "CMccCodecDTMF::CreateFmtpAttrListL" )
       
   324 
       
   325     RArray<TUint> toneNumbers;
       
   326     CleanupClosePushL( toneNumbers );
       
   327     
       
   328     GetAllowedToneNumbersArrayL( toneNumbers );
       
   329     CreateFmtpAttrListL( toneNumbers );
       
   330     
       
   331     CleanupStack::PopAndDestroy(); // toneNumbers
       
   332     
       
   333     __INTERFACE( "CMccCodecDTMF::CreateFmtpAttrListL, exit" )
       
   334 
       
   335     }
       
   336     
       
   337 // -----------------------------------------------------------------------------
       
   338 // CMccCodecDTMF::ParseFmtpAttrL
       
   339 // -----------------------------------------------------------------------------
       
   340 //       
       
   341 TBool CMccCodecDTMF::ParseFmtpAttrL( const TDesC8& aFmtp )
       
   342     {
       
   343     __INTERFACE( "CMccCodecDTMF::ParseFmtpAttrL" )      
       
   344     __INTERFACE_STR( "CMccCodecDTMF::ParseFmtpAttrL, fmtpValue=", aFmtp )
       
   345     
       
   346     /*
       
   347     a=fmtp:<format> <list of values>
       
   348     The list of values consists of comma-separated elements, which can be
       
   349     either a single decimal number or two decimal numbers separated by a
       
   350     hyphen (dash), where the second number is larger than the first. No
       
   351     whitespace is allowed between numbers or hyphens. The list does not
       
   352     have to be sorted.
       
   353     */
       
   354     
       
   355     TBool updated = EFalse;
       
   356     
       
   357     if ( aFmtp.Length() > 0 )
       
   358         {
       
   359         // white space is not allowed 
       
   360         if ( aFmtp.Locate( KCharSpace ) >= 0 )
       
   361             {
       
   362             User::Leave( KErrArgument );  
       
   363             }
       
   364            
       
   365         CPtrC8Array* tokens = TokenizeL( aFmtp, KCharComma );
       
   366         CleanupStack::PushL( tokens );
       
   367         
       
   368         // Mask will be updated while parsing
       
   369         iBitrateMask = 0;
       
   370         
       
   371         updated = EncodeTokensL( *tokens );
       
   372         
       
   373         CleanupStack::PopAndDestroy( tokens );
       
   374         }
       
   375     
       
   376     __INTERFACE( "CMccCodecDTMF::ParseFmtpAttrL, exit" )   
       
   377     
       
   378     return updated;
       
   379     }
       
   380  
       
   381 // -----------------------------------------------------------------------------
       
   382 // CMccCodecDTMF::TokenizeL
       
   383 // -----------------------------------------------------------------------------
       
   384 //  
       
   385 CPtrC8Array* CMccCodecDTMF::TokenizeL( const TDesC8& aValue,
       
   386                                        const TChar& aSeparator )
       
   387     {
       
   388     __INTERFACE( "CMccCodecDTMF::TokenizeLC" )      
       
   389 
       
   390 	__ASSERT_ALWAYS ( aValue.Length() > 0, User::Leave(KErrArgument) ); 
       
   391 	__ASSERT_ALWAYS ( aSeparator == KCharComma, User::Leave(KErrArgument) ); 
       
   392 
       
   393     CPtrC8Array* tokens = new (ELeave) CPtrC8Array(1);  
       
   394     CleanupStack::PushL( tokens );
       
   395     
       
   396 	TLex8 lex(aValue);
       
   397 	TChar chr = lex.Get();
       
   398     TInt previuosCommaPos = -1;
       
   399     TInt currentCommaPos = 0;
       
   400     
       
   401 	while ( chr )
       
   402 		{
       
   403 		// seperator (comma ',') found
       
   404 		if (chr == aSeparator)
       
   405 			{
       
   406 		    AddTokenL( *tokens, aValue, previuosCommaPos+1, currentCommaPos-1 );
       
   407 		    
       
   408     		previuosCommaPos = currentCommaPos; 
       
   409 			}
       
   410     	chr = lex.Get();
       
   411     
       
   412         currentCommaPos++;
       
   413 		}
       
   414     
       
   415     // the token is last one or first one without comma found
       
   416     if ( ( currentCommaPos - previuosCommaPos ) > 1 )
       
   417         {
       
   418         AddTokenL( *tokens, aValue, previuosCommaPos+1, currentCommaPos-1 );
       
   419         }
       
   420     else // token error
       
   421         {
       
   422         User::Leave( KErrArgument );   
       
   423         }
       
   424     
       
   425     CleanupStack::Pop( tokens );
       
   426     
       
   427     __INTERFACE( "CMccCodecDTMF::TokenizeLC, exit" )      
       
   428 
       
   429     return tokens;
       
   430     }
       
   431     
       
   432 // -----------------------------------------------------------------------------
       
   433 // CMccCodecDTMF::AddTokenL
       
   434 // -----------------------------------------------------------------------------
       
   435 //  
       
   436 void CMccCodecDTMF::AddTokenL ( CPtrC8Array& aTokenArray, 
       
   437                                 const TDesC8& aValue, 
       
   438                                 TInt aTokenStartPos,
       
   439                                 TInt aTokenEndPos )
       
   440     {
       
   441     __INTERFACE( "CMccCodecDTMF::AddTokenL" )      
       
   442 
       
   443 	__ASSERT_ALWAYS ( aTokenStartPos >= 0, User::Leave(KErrArgument) ); 
       
   444     __ASSERT_ALWAYS ( aTokenEndPos >= 0, User::Leave(KErrArgument) ); 
       
   445     __ASSERT_ALWAYS ( aTokenStartPos <= aTokenEndPos, User::Leave(KErrArgument) ); 
       
   446     
       
   447     TUint8 tokenlength = aTokenEndPos - aTokenStartPos + 1;
       
   448 	TPtrC8 token ( aValue.Mid(  aTokenStartPos , tokenlength ) );
       
   449 
       
   450 	aTokenArray.AppendL(token);
       
   451 	
       
   452 	__INTERFACE( "CMccCodecDTMF::AddTokenL, exit" )      
       
   453 
       
   454     }
       
   455            
       
   456 // -----------------------------------------------------------------------------
       
   457 // CMccCodecDTMF::EncodeTokensL
       
   458 // -----------------------------------------------------------------------------
       
   459 //  
       
   460 TBool CMccCodecDTMF::EncodeTokensL( MDesC8Array& aTokenArray )
       
   461     {
       
   462     __INTERFACE( "CMccCodecDTMF::EncodeTokensL" )      
       
   463 
       
   464     __ASSERT_ALWAYS ( aTokenArray.MdcaCount() > 0, User::Leave(KErrArgument) ); 
       
   465 
       
   466     TBool updated = EFalse;
       
   467     
       
   468     for ( TInt i=0; i < aTokenArray.MdcaCount(); i++ )
       
   469         {
       
   470         if ( ParseTokenL(aTokenArray.MdcaPoint( i )) ) 
       
   471             {
       
   472             updated = ETrue;   
       
   473             }
       
   474         }
       
   475      
       
   476     __INTERFACE( "CMccCodecDTMF::EncodeTokensL, exit" )      
       
   477 
       
   478     return updated;
       
   479     }
       
   480  
       
   481 // -----------------------------------------------------------------------------
       
   482 // CMccCodecDTMF::ParseTokenL
       
   483 // -----------------------------------------------------------------------------
       
   484 //       
       
   485 TBool CMccCodecDTMF::ParseTokenL( const TDesC8& aValue )
       
   486     {
       
   487     __INTERFACE( "CMccCodecDTMF::ParseTokenL" )      
       
   488     
       
   489     __ASSERT_ALWAYS ( aValue.Length() > 0, User::Leave(KErrArgument) ); 
       
   490     
       
   491     TBool updated = EFalse;
       
   492     
       
   493     TLex8 lex(aValue);
       
   494 	TChar chr = lex.Get();
       
   495 	TUint8 numberofHyphens = 0;
       
   496 	while (chr)
       
   497 		{
       
   498 		// token must contain digit numbers, 
       
   499 		// which may seperated by hyphens '-', 
       
   500 		// e.g 0-15 or e.g 60 or e.g 7
       
   501 		if ( chr == KCharHyphen )
       
   502     		{
       
   503     		++numberofHyphens;
       
   504     		}
       
   505     	// token must contains position digit number or one hyphen
       
   506 		if ( ( chr != KCharHyphen && !chr.IsDigit() ) || numberofHyphens > 1 )
       
   507 			{
       
   508 		    User::Leave( KErrArgument );
       
   509 			}
       
   510 	    chr = lex.Get();
       
   511 		} 
       
   512     
       
   513     // try to find the hyphen '-', aValue might contains
       
   514     // e.g 1-15,60,70 or 60,70
       
   515     TInt hyphenPosition = aValue.Locate( KCharHyphen );
       
   516     
       
   517     // the aValue does not contain hyphen '-', e.g 60
       
   518 	if ( hyphenPosition < 0 )
       
   519     	{
       
   520         updated	= ParseToneNumberL( aValue );
       
   521     	}
       
   522     // the aValue contains hyphen '-', e.g 0-15
       
   523     else if ( hyphenPosition > 0 && hyphenPosition < aValue.Length() )
       
   524         {
       
   525         TPtrC8 leftside ( aValue.Left(hyphenPosition) );
       
   526         TPtrC8 rightside ( aValue.Right( aValue.Length() - hyphenPosition - 1) );
       
   527         updated = ParseToneNumbersL( leftside, rightside );   
       
   528         }
       
   529     // the aValue is wrong, e.g -70 or 60-
       
   530     else 
       
   531         {
       
   532         User::Leave( KErrArgument );   
       
   533         }
       
   534 	
       
   535 	__INTERFACE( "CMccCodecDTMF::ParseTokenL, exit" )      
       
   536 
       
   537 	return updated;
       
   538     }
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CMccCodecDTMF::ParseToneNumberL
       
   542 // -----------------------------------------------------------------------------
       
   543 //                          
       
   544 TBool CMccCodecDTMF::ParseToneNumberL( const TDesC8& aValue )
       
   545     {
       
   546     __INTERFACE( "CMccCodecDTMF::ParserToneNumberL" )      
       
   547 
       
   548     __ASSERT_ALWAYS ( aValue.Length() > 0, User::Leave(KErrArgument) ); 
       
   549     
       
   550     TBool updated = EFalse;
       
   551     
       
   552     TLex8 myLex ( aValue );
       
   553     TUint myNumber;
       
   554     User::LeaveIfError( myLex.Val( myNumber, EDecimal ) );
       
   555     
       
   556     if ( myNumber <= 15 )
       
   557         {
       
   558         updated = AddAllowedBit( myNumber );
       
   559         }
       
   560         
       
   561     return updated;
       
   562     }
       
   563     
       
   564 // -----------------------------------------------------------------------------
       
   565 // CMccCodecDTMF::ParseToneNumbersL
       
   566 // -----------------------------------------------------------------------------
       
   567 //     
       
   568 TBool CMccCodecDTMF::ParseToneNumbersL( const TDesC8& aValueLeft, 
       
   569                                         const TDesC8& aValueRitght )
       
   570     {
       
   571     __INTERFACE( "CMccCodecDTMF::ParserToneNumbersL" )      
       
   572 
       
   573     __ASSERT_ALWAYS ( aValueLeft.Length() > 0, User::Leave(KErrArgument) ); 
       
   574     __ASSERT_ALWAYS ( aValueRitght.Length() > 0, User::Leave(KErrArgument) ); 
       
   575 
       
   576     TBool updated = EFalse;
       
   577     
       
   578     TLex8 myLeftLex ( aValueLeft );
       
   579     TUint myLeftNumber;
       
   580     User::LeaveIfError( myLeftLex.Val( myLeftNumber, EDecimal ) );
       
   581     
       
   582     TLex8 myRightLex ( aValueRitght );
       
   583     TUint myRightNumber;
       
   584     User::LeaveIfError( myRightLex.Val( myRightNumber, EDecimal ) );
       
   585     
       
   586     updated = AddToneNumbersL( myLeftNumber, myRightNumber );
       
   587     
       
   588     return updated;
       
   589     }
       
   590         
       
   591 // -----------------------------------------------------------------------------
       
   592 // CMccCodecDTMF::AddToneNumbersL
       
   593 // -----------------------------------------------------------------------------
       
   594 //   
       
   595 TBool CMccCodecDTMF::AddToneNumbersL( TUint aLeftNumber, TUint aRightNumber )
       
   596     {
       
   597     __INTERFACE( "CMccCodecDTMF::AddToneNumbersL" )      
       
   598 
       
   599     __ASSERT_ALWAYS ( aLeftNumber < aRightNumber, User::Leave(KErrArgument) ); 
       
   600 
       
   601     TBool updated = EFalse;
       
   602     
       
   603     TInt i = aLeftNumber > 0 ? aLeftNumber : 0;
       
   604     
       
   605     // if is DTMF tone, save DTMF tone numbers(0-15) to iBitrateMask
       
   606     for ( ;i <= (TInt) aRightNumber && i <= 15; i++ )
       
   607         {
       
   608         updated = AddAllowedBit( i );
       
   609         }
       
   610         
       
   611     return updated;
       
   612     }
       
   613     
       
   614 // -----------------------------------------------------------------------------
       
   615 // CMccCodecDTMF::GetAllowedToneNumbersArrayL
       
   616 // -----------------------------------------------------------------------------
       
   617 // 
       
   618 void CMccCodecDTMF::GetAllowedToneNumbersArrayL( RArray<TUint>& aToneNumbers )
       
   619     {
       
   620     __INTERFACE( "CMccCodecDTMF::GetAllowedToneNumbersArray" )      
       
   621 
       
   622     if ( iBitrateMask & KMccAllowedDtmfNumber0 )
       
   623         { 
       
   624         aToneNumbers.InsertInOrderL( KDtmfNumber0 );          
       
   625         }
       
   626     if ( iBitrateMask & KMccAllowedDtmfNumber1 )
       
   627         {
       
   628         aToneNumbers.InsertInOrderL( KDtmfNumber1 );          
       
   629         }
       
   630     if ( iBitrateMask & KMccAllowedDtmfNumber2 )
       
   631         {
       
   632         aToneNumbers.InsertInOrderL( KDtmfNumber2 );          
       
   633         }
       
   634     if ( iBitrateMask & KMccAllowedDtmfNumber3 )
       
   635         {
       
   636         aToneNumbers.InsertInOrderL( KDtmfNumber3 );
       
   637         }
       
   638     if ( iBitrateMask & KMccAllowedDtmfNumber4 )
       
   639         {
       
   640         aToneNumbers.InsertInOrderL( KDtmfNumber4 );
       
   641         }
       
   642     if ( iBitrateMask & KMccAllowedDtmfNumber5 )
       
   643         {
       
   644         aToneNumbers.InsertInOrderL( KDtmfNumber5 );
       
   645         }
       
   646     if ( iBitrateMask & KMccAllowedDtmfNumber6 )
       
   647         {
       
   648         aToneNumbers.InsertInOrderL( KDtmfNumber6 );
       
   649         }
       
   650     if ( iBitrateMask & KMccAllowedDtmfNumber7 )
       
   651         {
       
   652         aToneNumbers.InsertInOrderL( KDtmfNumber7 );
       
   653         }
       
   654     if ( iBitrateMask & KMccAllowedDtmfNumber8 )
       
   655         {
       
   656         aToneNumbers.InsertInOrderL( KDtmfNumber8 );
       
   657         }
       
   658     if ( iBitrateMask & KMccAllowedDtmfNumber9 )
       
   659         {
       
   660         aToneNumbers.InsertInOrderL( KDtmfNumber9 );
       
   661         }
       
   662     if ( iBitrateMask & KMccAllowedDtmfNumber10 )
       
   663         {
       
   664         aToneNumbers.InsertInOrderL( KDtmfNumber10 );
       
   665         }
       
   666     if ( iBitrateMask & KMccAllowedDtmfNumber11 )
       
   667         {
       
   668         aToneNumbers.InsertInOrderL( KDtmfNumber11 );
       
   669         }
       
   670     if ( iBitrateMask & KMccAllowedDtmfNumber12 )
       
   671         {
       
   672         aToneNumbers.InsertInOrderL( KDtmfNumber12 );
       
   673         }
       
   674     if ( iBitrateMask & KMccAllowedDtmfNumber13 )
       
   675         {
       
   676         aToneNumbers.InsertInOrderL( KDtmfNumber13 );
       
   677         }
       
   678     if ( iBitrateMask & KMccAllowedDtmfNumber14 )
       
   679         {
       
   680         aToneNumbers.InsertInOrderL( KDtmfNumber14 );
       
   681         }
       
   682     if ( iBitrateMask & KMccAllowedDtmfNumber15 )
       
   683         {
       
   684         aToneNumbers.InsertInOrderL( KDtmfNumber15 );
       
   685         }  
       
   686     }
       
   687   
       
   688 // -----------------------------------------------------------------------------
       
   689 // CMccCodecDTMF::CreateFmtpAttrListL
       
   690 // -----------------------------------------------------------------------------
       
   691 //       
       
   692 void CMccCodecDTMF::CreateFmtpAttrListL( const RArray<TUint>& aToneNumbers )
       
   693     {
       
   694     __INTERFACE( "CMccCodecDTMF::CreateFmtpAttrListL" )      
       
   695 
       
   696     delete iFmtpAttr;
       
   697     iFmtpAttr = NULL;
       
   698     iFmtpAttr = HBufC8::NewL( KMaxFmtpAttrLength ); 
       
   699    
       
   700     // if aToneNumbers contain e.g 2,3,4,5,7,9,10,11,12,13
       
   701     // it will append to iFmtpAttr like "1-5,7,9-13"
       
   702     TUint firstPos = 0;
       
   703     TUint nextpos = 0;
       
   704  
       
   705     while ( (TInt) nextpos < aToneNumbers.Count() )
       
   706         {
       
   707         FindContinuusIntegers( aToneNumbers, nextpos );
       
   708         if ( firstPos == nextpos ) 
       
   709             {
       
   710             iFmtpAttr->Des().AppendNum( aToneNumbers[ nextpos ] );
       
   711             }
       
   712         else if ( firstPos < nextpos )
       
   713             {
       
   714             iFmtpAttr->Des().AppendNum( aToneNumbers[ firstPos ] );
       
   715             iFmtpAttr->Des().Append( KCharHyphen );
       
   716             iFmtpAttr->Des().AppendNum( aToneNumbers[ nextpos ] );
       
   717             }
       
   718         if ( nextpos != aToneNumbers.Count() - 1 )
       
   719             {
       
   720             iFmtpAttr->Des().Append( KCharComma );
       
   721             }
       
   722         ++nextpos; 
       
   723         firstPos = nextpos;
       
   724         }
       
   725  
       
   726     }
       
   727  
       
   728 // -----------------------------------------------------------------------------
       
   729 // CMccCodecDTMF::AddAllowedBit
       
   730 // -----------------------------------------------------------------------------
       
   731 //       
       
   732 TBool CMccCodecDTMF::AddAllowedBit( TUint aBit )
       
   733     { 
       
   734     __INTERFACE( "CMccCodecDTMF::AddAllowedBit" )      
       
   735 
       
   736     TBool updated = EFalse;
       
   737  
       
   738     switch ( aBit )
       
   739         {
       
   740         case KDtmfNumber0:
       
   741             {
       
   742             iBitrateMask |= KMccAllowedDtmfNumber0;
       
   743             updated = ETrue;
       
   744             break;
       
   745             }
       
   746         case KDtmfNumber1:
       
   747             {
       
   748             iBitrateMask |= KMccAllowedDtmfNumber1;
       
   749             updated = ETrue;
       
   750             break;
       
   751             }
       
   752         case KDtmfNumber2:
       
   753             {
       
   754             iBitrateMask |= KMccAllowedDtmfNumber2;
       
   755             updated = ETrue;
       
   756             break;
       
   757             }
       
   758         case KDtmfNumber3:
       
   759             {
       
   760             iBitrateMask |= KMccAllowedDtmfNumber3;
       
   761             updated = ETrue;
       
   762             break;
       
   763             }
       
   764         case KDtmfNumber4:
       
   765             {
       
   766             iBitrateMask |= KMccAllowedDtmfNumber4;
       
   767             updated = ETrue;
       
   768             break;
       
   769             }
       
   770         case KDtmfNumber5:
       
   771             {
       
   772             iBitrateMask |= KMccAllowedDtmfNumber5;
       
   773             updated = ETrue;
       
   774             break;
       
   775             }
       
   776         case KDtmfNumber6:
       
   777             {
       
   778             iBitrateMask |= KMccAllowedDtmfNumber6;
       
   779             updated = ETrue;
       
   780             break;
       
   781             }
       
   782         case KDtmfNumber7:
       
   783             {
       
   784             iBitrateMask |= KMccAllowedDtmfNumber7;
       
   785             updated = ETrue;
       
   786             break;
       
   787             }
       
   788         case KDtmfNumber8:
       
   789             {
       
   790             iBitrateMask |= KMccAllowedDtmfNumber8;
       
   791             updated = ETrue;
       
   792             break;
       
   793             }
       
   794         case KDtmfNumber9:
       
   795             {
       
   796             iBitrateMask |= KMccAllowedDtmfNumber9;
       
   797             updated = ETrue;
       
   798             break;
       
   799             }
       
   800         case KDtmfNumber10:
       
   801             {
       
   802             iBitrateMask |= KMccAllowedDtmfNumber10;
       
   803             updated = ETrue;
       
   804             break;
       
   805             }
       
   806         case KDtmfNumber11:
       
   807             {
       
   808             iBitrateMask |= KMccAllowedDtmfNumber11;
       
   809             updated = ETrue;
       
   810             break;
       
   811             }
       
   812         case KDtmfNumber12:
       
   813             {
       
   814             iBitrateMask |= KMccAllowedDtmfNumber12;
       
   815             updated = ETrue;
       
   816             break;
       
   817             }
       
   818         case KDtmfNumber13:
       
   819             {
       
   820             iBitrateMask |= KMccAllowedDtmfNumber13;
       
   821             updated = ETrue;
       
   822             break;
       
   823             }
       
   824         case KDtmfNumber14:
       
   825             {
       
   826             iBitrateMask |= KMccAllowedDtmfNumber14;
       
   827             updated = ETrue;
       
   828             break;
       
   829             }
       
   830         case KDtmfNumber15:
       
   831             {
       
   832             iBitrateMask |= KMccAllowedDtmfNumber15;
       
   833             updated = ETrue;
       
   834             break;
       
   835             }
       
   836         default:
       
   837             {
       
   838             updated = EFalse;
       
   839             break;
       
   840             }
       
   841         }
       
   842    
       
   843     return updated;    
       
   844     }
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // CMccCodecDTMF::FindContinuusIntegers
       
   848 // -----------------------------------------------------------------------------
       
   849 // 
       
   850 void CMccCodecDTMF::FindContinuusIntegers( const RArray<TUint>& aToneNumbers, 
       
   851                                             TUint& aPosition  )
       
   852     {
       
   853     TBool found = EFalse;
       
   854     for ( TInt i=aPosition+1; i < aToneNumbers.Count() && !found; i++ )
       
   855         {
       
   856         if ( aToneNumbers[i-1] + 1 != aToneNumbers[i] )
       
   857             {
       
   858             aPosition = i-1;
       
   859             found = ETrue;    
       
   860             }
       
   861         if ( !found && i == ( aToneNumbers.Count() - 1 ) )
       
   862             {
       
   863             aPosition = i;   
       
   864             }
       
   865         }
       
   866     }
       
   867                         
       
   868 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   869 
       
   870 //  End of File