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