multimediacommscontroller/mmccinterface/src/mmcccodecamr.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 AMR CodecInformation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <delimitedpathsegment8.h>
       
    23 
       
    24 #include "mmcccodecamr.h"
       
    25 #include "mccuids.hrh"
       
    26 #include "mmccinterfacelogs.h"
       
    27 
       
    28 
       
    29 // CONSTANTS
       
    30 const TInt KUndefinedMode( -1 );
       
    31 const TInt KMaxModeSetValue( 8 );
       
    32 
       
    33 const TInt KNotSet = -1;
       
    34 
       
    35 const TInt KNumValue1 = 1;
       
    36 const TInt KNumValue2 = 2;
       
    37 
       
    38 // MODULE DATA STRUCTURES
       
    39 
       
    40 const TUint8 KAmrKAPayloadSize = 6;
       
    41 const TUint8 KAmrKeepAlivePayload[KAmrKAPayloadSize] = 
       
    42     { 
       
    43     0xF4, 0x00, 0x00, 0x00, 0x00, 0x00
       
    44     };
       
    45     
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CMccCodecAMR::CMccCodecAMR
       
    50 // default constructor
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CMccCodecAMR::CMccCodecAMR() : CMccCodecInformation()
       
    54     {
       
    55     iBitrateMask = KMccAllowedAmrNbBitrateAll;
       
    56     iMaxRed = KNotSet;
       
    57     iDefaultBitrateMask = KMccAllowedAmrNbBitrateAll;
       
    58     iDefaultBitrate = KAmrNbBitrate122;
       
    59     iAdditionalInfoMask = KMccAllowedAmrAdditionalInfo;
       
    60     iMaxModeSetVal = KMaxModeSetValue;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CMccCodecAMR::ConstructL
       
    65 // Symbian 2nd phase constructor can leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CMccCodecAMR::ConstructL( )
       
    69     {
       
    70     __INTERFACE( "CMccCodecAMR::ConstructL" )      
       
    71     iSdpName.Copy( KAMRSdpName );
       
    72     iKeepAliveData.Copy( KAmrKeepAlivePayload );
       
    73     iFmtpAttr = HBufC8::NewL( 1 );
       
    74     TPtr8 ptr = iFmtpAttr->Des();
       
    75     ptr.Append( KNullDesC );
       
    76     
       
    77     iFourCC = KMccFourCCIdAMRNB;
       
    78     SetSamplingFreq( KAmrNbSamplingFreq );
       
    79     EnableVAD( EFalse );
       
    80     iHwFrameTime = KAMRDefaultHwFrameTime; // default 20ms
       
    81     iFrameSize = KAMRDefaultFrameSize;
       
    82     SetMaxPTime( KAMRDefaultMaxPTime ); // recommended "limit" 200ms
       
    83     SetPTime( KAMRDefaultPTime ); // default 20ms 
       
    84     SetBitrate( KAmrNbBitrate122 ); // max bitrate
       
    85     SetPayloadType( KDefaultAmrNbPT );
       
    86     SetCodecMode( EBandwidthEfficient );
       
    87     iNumOfChannels = 1;
       
    88 
       
    89     iPayloadFormatEncoder = KImplUidAmrPayloadFormatEncode;
       
    90     iPayloadFormatDecoder = KImplUidAmrPayloadFormatDecode;
       
    91     
       
    92     __INTERFACE( "CMccCodecAMR::ConstructL, exit" )      
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CMccCodecAMR::NewL
       
    97 // Static constructor.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CMccCodecAMR* CMccCodecAMR::NewL()
       
   101     {
       
   102     CMccCodecAMR* self = new (ELeave) CMccCodecAMR;
       
   103     CleanupStack::PushL( self );
       
   104     self->ConstructL();
       
   105     CleanupStack::Pop( self ); 
       
   106     return self;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CMccCodecAMR::~CMccCodecAMR
       
   111 // Destructor
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 CMccCodecAMR::~CMccCodecAMR()
       
   115     {
       
   116     __INTERFACE( "CMccCodecAMR::~CMccCodecAMR" )      
       
   117     }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CMccCodecAMR::GetFmtpL
       
   122 // Gets the fmtp attribute
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 TDesC8& CMccCodecAMR::GetFmtpL()
       
   126     {
       
   127     __INTERFACE( "CMccCodecAMR::GetFmtpL" )      
       
   128     if ( iFmtpAttr )
       
   129         {
       
   130         delete iFmtpAttr;
       
   131         iFmtpAttr = NULL;
       
   132         }
       
   133     
       
   134     if( iBitrateMask )
       
   135         {
       
   136         RArray<TUint> array;
       
   137         CleanupClosePushL( array );
       
   138         
       
   139         if( GetAllowedBitratesArrayL( array ) == KErrNone )
       
   140             {
       
   141             CreateFmtpAttrListL( array );    
       
   142             }
       
   143         else
       
   144             {
       
   145             CreateFmtpAttrListL();        
       
   146             }
       
   147                 
       
   148         CleanupStack::Pop( &array );
       
   149         array.Close();
       
   150         }
       
   151     else
       
   152         {
       
   153         CreateFmtpAttrListL();    
       
   154         }
       
   155 
       
   156     
       
   157     __INTERFACE_STR( "CMccCodecAMR::GetFmtpL", *iFmtpAttr);     
       
   158     return *iFmtpAttr;    
       
   159     }
       
   160     
       
   161 // -----------------------------------------------------------------------------
       
   162 // CMccCodecAMR::GetBitrateModeSet
       
   163 // Get the mode from the bitrate
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 TInt CMccCodecAMR::GetBitrateModeSet( TUint aBitrate )
       
   167     {
       
   168     __INTERFACE( "CMccCodecAMR::GetBitrateModeSet" )      
       
   169     TInt mode( KUndefinedMode );
       
   170     
       
   171     switch ( aBitrate )
       
   172         {
       
   173         case KAmrNbBitrate475:
       
   174             {
       
   175             mode = KAMRMode0;
       
   176             break;
       
   177             }
       
   178         case KAmrNbBitrate515:
       
   179             {
       
   180             mode = KAMRMode1;
       
   181             break;
       
   182             }
       
   183         case KAmrNbBitrate590:
       
   184             {
       
   185             mode = KAMRMode2;
       
   186             break;
       
   187             }
       
   188         case KAmrNbBitrate670:
       
   189             {
       
   190             mode = KAMRMode3;
       
   191             break;
       
   192             }
       
   193         case KAmrNbBitrate740:
       
   194             {
       
   195             mode = KAMRMode4;
       
   196             break;
       
   197             }
       
   198         case KAmrNbBitrate795:
       
   199             {
       
   200             mode = KAMRMode5;
       
   201             break;
       
   202             }
       
   203         case KAmrNbBitrate102:
       
   204             {
       
   205             mode = KAMRMode6;
       
   206             break;
       
   207             }
       
   208         case KAmrNbBitrate122:
       
   209             {
       
   210             mode = KAMRMode7;
       
   211             break;
       
   212             }
       
   213         default:
       
   214             {
       
   215             break;
       
   216             }                
       
   217         }
       
   218         
       
   219     __INTERFACE_INT1( "CMccCodecAMR::GetBitrateModeSet, exit with mode", mode )      
       
   220     return mode;
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CMccCodecAMR::SetBitrateModeSet
       
   225 // Sets the bitrate used with AMR codec from the mode .
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 void CMccCodecAMR::SetBitrateModeSet( TUint aModeSet )
       
   229     {
       
   230     __INTERFACE( "CMccCodecAMR::SetBitrateModeSet" )      
       
   231     switch ( aModeSet )
       
   232         {
       
   233         case KAMRMode0:
       
   234             {
       
   235             SetBitrate( KAmrNbBitrate475 );
       
   236             break;
       
   237             }
       
   238         case KAMRMode1:
       
   239             {
       
   240             SetBitrate( KAmrNbBitrate515 );
       
   241             break;
       
   242             }
       
   243         case KAMRMode2:
       
   244             {
       
   245             SetBitrate( KAmrNbBitrate590 );
       
   246             break;
       
   247             }
       
   248         case KAMRMode3:
       
   249             {
       
   250             SetBitrate( KAmrNbBitrate670 );
       
   251             break;
       
   252             }
       
   253         case KAMRMode4:
       
   254             {
       
   255             SetBitrate( KAmrNbBitrate740 );
       
   256             break;
       
   257             }
       
   258         case KAMRMode5:
       
   259             {
       
   260             SetBitrate( KAmrNbBitrate795 );
       
   261             break;
       
   262             }
       
   263         case KAMRMode6:
       
   264             {
       
   265             SetBitrate( KAmrNbBitrate102 );
       
   266             break;
       
   267             }
       
   268         case KAMRMode7:
       
   269             {
       
   270             SetBitrate( KAmrNbBitrate122 );
       
   271             break;
       
   272             }
       
   273         default:
       
   274             {
       
   275             SetBitrate( KAmrNbBitrate475 );
       
   276             break;
       
   277             }
       
   278         }
       
   279     __INTERFACE( "CMccCodecAMR::SetBitrateModeSet, exit" )      
       
   280     }
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CMccCodecAMR::GetBitrateMaskFromMode
       
   284 // Get the bitrate mask from the mode
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 TInt CMccCodecAMR::GetBitrateMaskFromMode( TUint aMode, TUint& aBitrateMask  )
       
   288     {
       
   289     __INTERFACE( "CMccCodecAMR::GetBitrateMaskFromMode" )          
       
   290     switch ( aMode )
       
   291         {
       
   292         case KAMRMode0:
       
   293             {
       
   294             aBitrateMask = KMccAllowedAmrNbBitrate475;
       
   295             break;
       
   296             }
       
   297             
       
   298         case KAMRMode1:
       
   299             {
       
   300             aBitrateMask = KMccAllowedAmrNbBitrate515;
       
   301             break;
       
   302             }
       
   303             
       
   304         case KAMRMode2:
       
   305             {
       
   306             aBitrateMask = KMccAllowedAmrNbBitrate590;
       
   307             break;
       
   308             }
       
   309             
       
   310         case KAMRMode3:
       
   311             {
       
   312             aBitrateMask = KMccAllowedAmrNbBitrate670;
       
   313             break;
       
   314             }
       
   315         case KAMRMode4:
       
   316             {
       
   317             aBitrateMask = KMccAllowedAmrNbBitrate740;
       
   318             break;
       
   319             }
       
   320         case KAMRMode5:
       
   321             {
       
   322             aBitrateMask = KMccAllowedAmrNbBitrate795;
       
   323             break;
       
   324             }
       
   325         case KAMRMode6:
       
   326             {
       
   327             aBitrateMask = KMccAllowedAmrNbBitrate102;
       
   328             break;
       
   329             }
       
   330         case KAMRMode7:
       
   331             {
       
   332             aBitrateMask = KMccAllowedAmrNbBitrate122;
       
   333             break;
       
   334             }
       
   335         
       
   336         default:
       
   337             {
       
   338             __INTERFACE( "CMccCodecAMR::GetBitrateMaskFromMode, exit KErrNotFound" )          
       
   339             return KErrNotFound; 
       
   340             }                
       
   341         }
       
   342     
       
   343     __INTERFACE( "CMccCodecAMR::GetBitrateMaskFromMode, exit" )          
       
   344     return KErrNone;
       
   345     }
       
   346     
       
   347 // -----------------------------------------------------------------------------
       
   348 // CMccCodecAMR::CreateFmtpModeSet
       
   349 // Creates the mode-set value of the FMTP according to the bitrates
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 TBool CMccCodecAMR::CreateFmtpModeSet( TDes8& aBuf,
       
   353                                        const RArray<TUint>& aBitrates )
       
   354     {
       
   355     __INTERFACE( "CMccCodecAMR::CreateFmtpModeSet" )          
       
   356     TInt tempMode;
       
   357     TBool modeSetStringAdded( EFalse );
       
   358     _LIT8( KTxtTempMode, "%d" );
       
   359     _LIT8( KTxtComma, "," );
       
   360 
       
   361     TInt count( aBitrates.Count() );
       
   362     
       
   363     if ( count > iMaxModeSetVal )
       
   364         {
       
   365         return modeSetStringAdded;
       
   366         }
       
   367         
       
   368     for ( TInt i = 0; i < count; i++ )
       
   369         {
       
   370         tempMode = this->GetBitrateModeSet( aBitrates[i] );
       
   371         // Do not modify the buffer until we have a recognized mode value
       
   372         if ( tempMode >= 0 )
       
   373             {
       
   374             if ( !modeSetStringAdded )
       
   375                 {
       
   376                 // Insert the mode string before the first value
       
   377                 aBuf.Append( KTxtModeSet ); // "mode-set="
       
   378                 modeSetStringAdded = ETrue;
       
   379                 
       
   380                 // Also clear the bitrate mask
       
   381                 SetBitrateMask( 0, ETrue );
       
   382                 }
       
   383             else
       
   384                 {
       
   385                 // Insert a comma before all other values
       
   386                 aBuf.Append( KTxtComma );
       
   387                 }
       
   388             // Update the bitrate mask
       
   389             TUint currentMask( 0 );
       
   390             GetBitrateMaskFromMode( tempMode, currentMask );
       
   391             
       
   392             SetBitrateMask( ( iBitrateMask | currentMask ), ETrue );
       
   393             
       
   394             // Update the FMTP string
       
   395             aBuf.AppendFormat( KTxtTempMode, tempMode );
       
   396             }
       
   397         }
       
   398     __INTERFACE( "CMccCodecAMR::CreateFmtpModeSet, exit" )          
       
   399     return modeSetStringAdded;
       
   400     }
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CMccCodecAMR::SetBitrate
       
   404 // Sets the bitrate used with AMR codec.
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 TInt CMccCodecAMR::SetBitrate( TUint aBitrate )
       
   408     {
       
   409     TBool isValid( ETrue );
       
   410        
       
   411     switch ( aBitrate )
       
   412         {
       
   413         case KAmrNbBitrate475:
       
   414             break;
       
   415         case KAmrNbBitrate515:
       
   416             break;
       
   417         case KAmrNbBitrate590:
       
   418             break;
       
   419         case KAmrNbBitrate670:
       
   420             break;
       
   421         case KAmrNbBitrate740:
       
   422             break;
       
   423         case KAmrNbBitrate795:
       
   424             break;
       
   425         case KAmrNbBitrate102:
       
   426             break;
       
   427         case KAmrNbBitrate122:
       
   428             break;
       
   429         default:
       
   430             isValid = EFalse;
       
   431             break;
       
   432         }
       
   433     if ( isValid )
       
   434         {
       
   435         iBitrate = aBitrate;
       
   436         return KErrNone;
       
   437         }
       
   438     else
       
   439         {
       
   440         return KErrNotSupported;
       
   441         }
       
   442     }
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 // CMccCodecAMR::SetBitrateFromBitrateMask
       
   446 // Sets the bitrate used with AMR codec from the bitrateMask.
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 TInt CMccCodecAMR::SetBitrateFromBitrateMask( TUint aBitrateMask )
       
   450     {
       
   451     if ( aBitrateMask & KMccAllowedModeChangePeriod2 )
       
   452         {
       
   453         SetModeChangePeriod( KNumValue2 );
       
   454         }
       
   455     
       
   456     if ( aBitrateMask & KMccAllowedModeChangeNeighbor1 )
       
   457         {
       
   458         SetModeChangeNeighbor( ETrue );
       
   459         }
       
   460         
       
   461     if( aBitrateMask & KMccAllowedAmrNbBitrate122 )
       
   462         {
       
   463         SetBitrate( KAmrNbBitrate122 );
       
   464         return KErrNone;
       
   465         }
       
   466     else if( aBitrateMask & KMccAllowedAmrNbBitrate102 )
       
   467         {
       
   468         SetBitrate( KAmrNbBitrate102 );
       
   469         return KErrNone;
       
   470         }
       
   471     else if( aBitrateMask & KMccAllowedAmrNbBitrate795 )
       
   472         {
       
   473         SetBitrate( KAmrNbBitrate795 );
       
   474         return KErrNone;
       
   475         }   
       
   476     else if( aBitrateMask & KMccAllowedAmrNbBitrate740 )
       
   477         {
       
   478         SetBitrate( KAmrNbBitrate740 );
       
   479         return KErrNone;
       
   480         }   
       
   481     else if( aBitrateMask & KMccAllowedAmrNbBitrate670 )
       
   482         {
       
   483         SetBitrate( KAmrNbBitrate670 );
       
   484         return KErrNone;
       
   485         }   
       
   486     else if( aBitrateMask & KMccAllowedAmrNbBitrate590 )
       
   487         {
       
   488         SetBitrate( KAmrNbBitrate590 );
       
   489         return KErrNone;
       
   490         }
       
   491     else if( aBitrateMask & KMccAllowedAmrNbBitrate515 )
       
   492         {
       
   493         SetBitrate( KAmrNbBitrate515 );
       
   494         return KErrNone;
       
   495         }  
       
   496     else if( aBitrateMask & KMccAllowedAmrNbBitrate475 )
       
   497         {
       
   498         SetBitrate( KAmrNbBitrate475 );
       
   499         return KErrNone;
       
   500         }
       
   501     else
       
   502         {
       
   503         return KErrArgument;    
       
   504         }
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CMccCodecAMR::SetSamplingFreq
       
   509 // Sets the sampling frequency. 
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 TInt CMccCodecAMR::SetSamplingFreq( TUint32 aSamplingFreq )
       
   513     {
       
   514     // AMR-WB is not supported yet
       
   515     if ( KAmrNbSamplingFreq == aSamplingFreq /* || KAmrWbSamplingFreq == aSamplingFreq */ )
       
   516         {
       
   517         iSamplingFreq = aSamplingFreq;
       
   518         return KErrNone;
       
   519         }
       
   520     else
       
   521         {
       
   522         return KErrNotSupported;
       
   523         }
       
   524     }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // CMccCodecAMR::SetSdpName
       
   528 // Sets the SDP name
       
   529 // -----------------------------------------------------------------------------
       
   530 TInt CMccCodecAMR::SetSdpName( const TDesC8& aSdpName )
       
   531     {
       
   532     if ( !aSdpName.CompareF( KAMRSdpName ) )
       
   533         {
       
   534         iSdpName.Copy( aSdpName );
       
   535         }
       
   536     else 
       
   537         {
       
   538         return KErrNotSupported;
       
   539         }
       
   540     
       
   541     return KErrNone;
       
   542     }
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // CMccCodecAMR::PayloadType
       
   546 // Sets the payload type
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 TInt CMccCodecAMR::SetPayloadType( TUint8 aPayloadType )
       
   550     {
       
   551     if ( aPayloadType < KMinDynamicPT ||
       
   552          aPayloadType > KMaxPayloadType ) 
       
   553         {
       
   554         return KErrArgument;
       
   555         }
       
   556     else 
       
   557         {
       
   558         iPayloadType = aPayloadType;
       
   559         return KErrNone;
       
   560         }
       
   561     }
       
   562     
       
   563 // -----------------------------------------------------------------------------
       
   564 // CMccCodecAMR::SetCodecMode
       
   565 // Sets the codec mode
       
   566 // -----------------------------------------------------------------------------
       
   567 //
       
   568 TInt CMccCodecAMR::SetCodecMode( TCodecMode aCodecMode )
       
   569     {
       
   570     if ( EBandwidthEfficient == aCodecMode || EOctetAligned == aCodecMode )
       
   571         {
       
   572         iCodecMode = aCodecMode;
       
   573         return KErrNone;
       
   574         }
       
   575     else
       
   576         {
       
   577         return KErrNotSupported;
       
   578         }
       
   579     }
       
   580  
       
   581 // -----------------------------------------------------------------------------
       
   582 // CMccCodecAMR::SetAllowedBitrates
       
   583 // Set allowed bitrates
       
   584 // -----------------------------------------------------------------------------
       
   585 //
       
   586 TInt CMccCodecAMR::SetAllowedBitrates( TUint aBitrateMask )
       
   587     {
       
   588     //Confirm that the bitrate mask is valid
       
   589     //I.e. after all the valid bitrates are set to zero the value should be zero
       
   590     if ( (aBitrateMask >> 12 ) > 0 )
       
   591         {
       
   592         return KErrArgument;
       
   593         }
       
   594     else
       
   595         {
       
   596         /*
       
   597         In the future the allowed bitrates will be fetched from the codec
       
   598         I.e. the KMccAllowedAmrNbBitrateAll will be changed to the bitrates
       
   599         supported by the codec
       
   600         */
       
   601         SetBitrateMask( KMccAllowedAmrNbBitrateAll & aBitrateMask );
       
   602         SetBitrateMaskAdditionalInfo( aBitrateMask );
       
   603         
       
   604         SetBitrateFromBitrateMask( iBitrateMask );
       
   605         }
       
   606     
       
   607     return KErrNone;
       
   608     }
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 // CMccCodecAMR::SetRedCount
       
   612 // Sets level of redundancy.
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 TInt CMccCodecAMR::SetRedCount( TUint aRedCount )
       
   616     {
       
   617     TInt retVal( KErrArgument );
       
   618     if ( iMaxRed != KNotSet )
       
   619         {
       
   620         if ( KMaxAmrFecRedCount >= aRedCount )
       
   621             {
       
   622             TAlgoUsed algo = aRedCount > 0 ? EAmrFecUsed : ENoAlgoUsed;
       
   623             SetAlgo( algo );
       
   624             iRedCount = aRedCount;
       
   625             retVal = KErrNone;
       
   626             }
       
   627         }
       
   628     else if ( KMaxGenRedCount >= aRedCount )
       
   629         {   
       
   630         TAlgoUsed algo = aRedCount > 0 ? EGenRedUsed : ENoAlgoUsed;
       
   631         SetAlgo( algo );
       
   632         iRedCount = aRedCount;
       
   633         retVal = KErrNone;
       
   634         }
       
   635     else
       
   636         {
       
   637         // NOP
       
   638         }
       
   639     return retVal;
       
   640     }
       
   641     
       
   642 // -----------------------------------------------------------------------------
       
   643 // CMccCodecAMR::GetAllowedBitratesArrayL
       
   644 // Get allowed bitrates in an array
       
   645 // -----------------------------------------------------------------------------
       
   646 //
       
   647 TInt CMccCodecAMR::GetAllowedBitratesArrayL( RArray<TUint>& aBitratesArray )
       
   648     {
       
   649     if( iBitrateMask & KMccAllowedAmrNbBitrate475 )
       
   650         {
       
   651         User::LeaveIfError( aBitratesArray.Append(  KAmrNbBitrate475 ) );
       
   652         }
       
   653     if( iBitrateMask & KMccAllowedAmrNbBitrate515 )
       
   654         {
       
   655         User::LeaveIfError( aBitratesArray.Append( KAmrNbBitrate515 ) );
       
   656         }
       
   657     if( iBitrateMask & KMccAllowedAmrNbBitrate590 )
       
   658         {
       
   659         User::LeaveIfError( aBitratesArray.Append( KAmrNbBitrate590 ) );
       
   660         }
       
   661     if( iBitrateMask & KMccAllowedAmrNbBitrate670 )
       
   662         {
       
   663         User::LeaveIfError( aBitratesArray.Append( KAmrNbBitrate670 ) );
       
   664         }
       
   665     if( iBitrateMask & KMccAllowedAmrNbBitrate740 )
       
   666         {
       
   667         User::LeaveIfError( aBitratesArray.Append( KAmrNbBitrate740 ) );
       
   668         }
       
   669     if( iBitrateMask & KMccAllowedAmrNbBitrate795 )
       
   670         {
       
   671         User::LeaveIfError( aBitratesArray.Append( KAmrNbBitrate795 ) );
       
   672         }
       
   673     if( iBitrateMask & KMccAllowedAmrNbBitrate102 )
       
   674         {
       
   675         User::LeaveIfError( aBitratesArray.Append( KAmrNbBitrate102 ) );
       
   676         }
       
   677     if( iBitrateMask & KMccAllowedAmrNbBitrate122 )
       
   678         {
       
   679         User::LeaveIfError( aBitratesArray.Append( KAmrNbBitrate122 ) );
       
   680         }
       
   681     
       
   682     return KErrNone;
       
   683     }
       
   684 
       
   685 // -----------------------------------------------------------------------------
       
   686 // CMccCodecAMR::EnableVAD
       
   687 // Enable / Disable VAD
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 TInt CMccCodecAMR::EnableVAD( TBool aEnableVAD ) 
       
   691     {
       
   692     iEnableVAD = aEnableVAD;        
       
   693     return KErrNone;
       
   694     }
       
   695     
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CMccCodecAMR::SetPTime
       
   699 // Set PTime
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 TInt CMccCodecAMR::SetPTime( TUint aPTime )
       
   703     {
       
   704     if ( ( aPTime <= iMaxPTime ) && (( aPTime % KDefaultPtime )  == 0 ) &&
       
   705          aPTime && ( KMinPtime < aPTime ) )
       
   706         {
       
   707         iPTime = aPTime;
       
   708         return KErrNone;    
       
   709         }
       
   710     else
       
   711         {
       
   712         return KErrArgument;
       
   713         }
       
   714     }
       
   715     
       
   716 // -----------------------------------------------------------------------------
       
   717 // CMccCodecAMR::SetMaxPTime
       
   718 // Set Max PTime
       
   719 // -----------------------------------------------------------------------------
       
   720 //
       
   721 TInt CMccCodecAMR::SetMaxPTime( TUint aMaxPTime )
       
   722     {
       
   723     if (  aMaxPTime && ( aMaxPTime <= KAMRDefaultMaxPTime ) &&
       
   724         ( ( aMaxPTime % KDefaultPtime )  == 0 ) && ( KMinPtime < aMaxPTime )
       
   725         && iPTime <= aMaxPTime )
       
   726         {
       
   727         iMaxPTime = aMaxPTime;
       
   728         return KErrNone;    
       
   729         }
       
   730     else
       
   731         {
       
   732         return KErrArgument;
       
   733         }
       
   734     }
       
   735     
       
   736 // -----------------------------------------------------------------------------
       
   737 // CMccCodecAMR::CloneDefaultsL
       
   738 // Make a default setting clone from this AMR codec
       
   739 // -----------------------------------------------------------------------------
       
   740 //
       
   741 CMccCodecInformation* CMccCodecAMR::CloneDefaultsL()
       
   742     {
       
   743     __INTERFACE( "CMccCodecAMR::CloneDefaultsL" )          
       
   744     return CMccCodecAMR::NewL();
       
   745     }
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // CMccCodecAMR::CloneDetailedL
       
   749 // Make a detailed clone from this AMR codec
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 CMccCodecInformation* CMccCodecAMR::CloneDetailedL()
       
   753     {
       
   754     CMccCodecAMR* newCodec = CMccCodecAMR::NewL();
       
   755     CleanupStack::PushL( newCodec );
       
   756     newCodec->SetBitrate( this->Bitrate() );
       
   757     newCodec->SetCodecMode( this->CodecMode() );
       
   758     newCodec->SetMaxPTime( this->MaxPTime() );
       
   759     newCodec->SetPayloadType( this->PayloadType() );
       
   760     newCodec->SetPTime( this->PTime() );
       
   761     newCodec->SetSamplingFreq( this->SamplingFreq() );
       
   762     newCodec->SetSdpName( this->SdpName() );
       
   763     newCodec->SetFmtpAttrL( this->GetFmtpL(), EFalse );
       
   764     CleanupStack::Pop( newCodec );
       
   765     return newCodec;
       
   766     }
       
   767  
       
   768 // -----------------------------------------------------------------------------
       
   769 // CMccCodecAMR::RequireSignalling
       
   770 // -----------------------------------------------------------------------------
       
   771 //
       
   772 TBool CMccCodecAMR::RequireSignalling(
       
   773     const CMccCodecInformation& aCandidate ) const      
       
   774     {
       
   775     __INTERFACE( "CMccCodecAMR::RequireSignalling" )
       
   776     TBool ret = EFalse;
       
   777               
       
   778     if ( iPTime != aCandidate.PTime() )
       
   779         {
       
   780         __INTERFACE( "CMccCodecAMR::RequireSignalling, PTime changed" )
       
   781         ret = ETrue;
       
   782         }
       
   783         
       
   784     if ( iMaxPTime != aCandidate.MaxPTime() )
       
   785         {
       
   786         __INTERFACE( "CMccCodecAMR::RequireSignalling, MaxPTime changed" )
       
   787         ret = ETrue;
       
   788         }
       
   789         
       
   790     if ( iPayloadType != aCandidate.PayloadType() )
       
   791         {
       
   792         __INTERFACE( "CMccCodecAMR::RequireSignalling, PayloadType changed" )
       
   793         ret = ETrue;
       
   794         }
       
   795 
       
   796 	__INTERFACE_INT1( "CMccCodecAMR::RequireSignalling, bitrate mask 1", iBitrateMask )
       
   797 	__INTERFACE_INT1( "CMccCodecAMR::RequireSignalling, bitrate mask 2", aCandidate.AllowedBitrates() )
       
   798   
       
   799 	if ( iBitrateMask != aCandidate.AllowedBitrates() )
       
   800         {
       
   801         if ( iBitrateMask != ( KMccAllowedModeChangeNeighbor1 | KMccAllowedAmrNbBitrateAll ) &&
       
   802         	 iBitrateMask != KMccAllowedModeChangeNeighbor1 )
       
   803         	{
       
   804         	__INTERFACE( "CMccCodecAMR::RequireSignalling, BitrateMask changed" )
       
   805         	ret = ETrue;
       
   806         	}
       
   807         if ( aCandidate.AllowedBitrates() != ( KMccAllowedModeChangeNeighbor1 |
       
   808         									   KMccAllowedAmrNbBitrateAll ) &&
       
   809         	 aCandidate.AllowedBitrates() != KMccAllowedModeChangeNeighbor1 )
       
   810         	{
       
   811         	__INTERFACE( "CMccCodecAMR::RequireSignalling, BitrateMask changed" )
       
   812         	ret = ETrue;
       
   813         	}
       
   814         }
       
   815 
       
   816     if ( iCodecMode != aCandidate.CodecMode() )
       
   817         {
       
   818         __INTERFACE( "CMccCodecAMR::RequireSignalling, CodecMode changed" )
       
   819         ret = ETrue;
       
   820         }
       
   821         
       
   822     __INTERFACE_INT1( "CMccCodecAMR::RequireSignalling, exit with", ret )
       
   823     return ret;          
       
   824     }
       
   825  
       
   826 // -----------------------------------------------------------------------------
       
   827 // CMccCodecAMR::ParseFmtpAttrL
       
   828 // Parse the fmtp string, but doesn't update the iFmtpAttr
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 TBool CMccCodecAMR::ParseFmtpAttrL( const TDesC8& aFmtp )
       
   832     {
       
   833     // These booleans needed in FMTP parsing to handle where parameters
       
   834     // not present in FMTP
       
   835 
       
   836     iModesExist = EFalse;
       
   837     iOctetAlignExist = EFalse;
       
   838     iModeChangePeriodExist = EFalse;
       
   839     iModeChangeNeighborExist = EFalse;
       
   840     iMaxRedExist = EFalse;
       
   841     
       
   842     //Remove all white space from begining and end,
       
   843     //Convert the content of the descriptor to lower case
       
   844     const TUint8* pointerC = aFmtp.Ptr();
       
   845     TUint8* pointer        = const_cast<TUint8*>( pointerC );
       
   846     TPtr8 descriptor( pointer, aFmtp.Length(), aFmtp.Length() );
       
   847     descriptor.Trim();
       
   848     
       
   849     /*
       
   850     TDelimitedPathSegmentParser8 Parses path segments whose 
       
   851     components are delimited by the ';' character, 
       
   852     as defined in RFC2396.
       
   853     */
       
   854     TDelimitedPathSegmentParser8 parser;
       
   855     parser.Parse( aFmtp );
       
   856     TPtrC8 segment;
       
   857     TBool updated( EFalse );
       
   858     
       
   859     while ( parser.GetNext( segment ) != KErrNotFound )
       
   860         {
       
   861         if ( ParseFmtpSegmentL( segment ) )
       
   862             {
       
   863             updated = ETrue;
       
   864             }
       
   865         }
       
   866     
       
   867     if ( !iModesExist )
       
   868         {
       
   869         // Allow all modes
       
   870         SetBitrateMask( iDefaultBitrateMask, ETrue );
       
   871         SetBitrate( iDefaultBitrate ); // max bitrate
       
   872         }
       
   873         
       
   874     if ( !iOctetAlignExist )
       
   875         {
       
   876         SetCodecMode( EBandwidthEfficient );
       
   877         }
       
   878     
       
   879     if ( !iModeChangePeriodExist )
       
   880         {
       
   881         SetModeChangePeriod( KDefaultModeChangePeriod );
       
   882         }
       
   883         
       
   884     if ( !iModeChangeNeighborExist )
       
   885         {
       
   886         SetModeChangeNeighbor( EFalse );
       
   887         }
       
   888         
       
   889     if ( !iMaxRedExist )
       
   890         {
       
   891         SetMaxRed( KNotSet );
       
   892         }   
       
   893                 
       
   894     return updated;
       
   895     }
       
   896 
       
   897 // -----------------------------------------------------------------------------
       
   898 // CMccCodecAMR::ParseFmtpSegmentL
       
   899 // Parse and updates the matched param
       
   900 // -----------------------------------------------------------------------------
       
   901 //    
       
   902 TBool CMccCodecAMR::ParseFmtpSegmentL( const TDesC8& aSeg )
       
   903     {
       
   904     TBool update( EFalse );
       
   905     _LIT8( KEqualSign, "=" );
       
   906     
       
   907     // Check for first '=' sign 
       
   908     TInt index = aSeg.Find( KEqualSign );
       
   909     
       
   910     if ( index > 0 )
       
   911         {
       
   912         // Check if match mode-set 
       
   913         if ( aSeg.Left( index ).Match( KMatchModeSet  ) != KErrNotFound )
       
   914             {
       
   915             update = ParseFmtpModeSetL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   916             iModesExist = ETrue;
       
   917             }      
       
   918         // Check if match octet-align
       
   919         else if ( aSeg.Left( index ).Match( KMatchOctetAlign ) != KErrNotFound )
       
   920             {
       
   921             update = ParseFmtpOctetAlignL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   922             iOctetAlignExist = ETrue;
       
   923             }
       
   924 
       
   925         // Check if match mode-change-period
       
   926         else if ( aSeg.Left( index ).Match( KMatchModeChangePeriod ) != KErrNotFound )
       
   927             {
       
   928             update = ParseFmtpModeChangePeriodL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   929             iModeChangePeriodExist = ETrue;
       
   930             }
       
   931         // Check if match mode-change-neighbor
       
   932         else if ( aSeg.Left( index ).Match( KMatchModeChangeNeighbor ) != KErrNotFound )
       
   933             {
       
   934             update = ParseFmtpModeChangeNeighborL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   935             iModeChangeNeighborExist = ETrue;
       
   936             }
       
   937         // Check if match crc
       
   938         else if ( aSeg.Left( index ).Match( KCrc ) != KErrNotFound )
       
   939             {
       
   940             update = ParseFmtpCrcL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   941             }
       
   942         // Check if match crc
       
   943         else if ( aSeg.Left( index ).Match( KRobustSorting ) != KErrNotFound )
       
   944             {
       
   945             update = ParseFmtpRobustSortingL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   946             }
       
   947         // Check if match interleaving
       
   948         else if ( aSeg.Left( index ).Match( KInterleaving ) != KErrNotFound )
       
   949             {
       
   950             update = ParseFmtpInterleavingL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   951             }
       
   952         else if ( aSeg.Left( index ).Match( KMaxRed ) != KErrNotFound )
       
   953             {
       
   954             update = ParseFmtpMaxRedL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   955             }              
       
   956         else
       
   957             {
       
   958             // Make PC-LINT happy.
       
   959             }
       
   960         }
       
   961   
       
   962     return update;
       
   963     }
       
   964 
       
   965 // -----------------------------------------------------------------------------
       
   966 // CMccCodecAMR::ParseFmtpModeSet
       
   967 // Parses and updates the bitrate
       
   968 // -----------------------------------------------------------------------------
       
   969 //      
       
   970 TBool CMccCodecAMR::ParseFmtpModeSetL( const TDesC8& aFmtpModeSet )
       
   971     {
       
   972     /**
       
   973      * RFC 3267, page 39
       
   974      *
       
   975      * mode-set: Requested AMR mode set. Restricts the active codec mode 
       
   976      * set to a subset of all modes. Possible values are a comma separetad
       
   977      * list of modes from the set: 0,..,7. If such mode set is specified by 
       
   978      * the decoder, the encoder MUST abide by the request and  MUST NOT use
       
   979      * modes outside of the subset. If not present, all codec modes are 
       
   980      * allowed for the session
       
   981      **/
       
   982      
       
   983     TInt err( KErrNone );
       
   984     TInt error( KErrNone );
       
   985     
       
   986     HBufC8* hBuf = HBufC8::NewLC( aFmtpModeSet.Length() );
       
   987 
       
   988     hBuf->Des().Copy( aFmtpModeSet );
       
   989     TPtr8 ptr( hBuf->Des() );
       
   990 
       
   991     // Convert descriptor to integer using TLex8
       
   992     TLex8 lex;
       
   993     TInt index( KErrNone );
       
   994     TInt maxValue( 0 );
       
   995     TInt currentValue( 0 );
       
   996     
       
   997     TUint bitrateMaskCurrent( 0 );
       
   998     TUint bitrateMaskUpdated( 0 );
       
   999     
       
  1000     TBool more( ETrue );
       
  1001     
       
  1002     while ( more )
       
  1003         {
       
  1004         ptr.TrimAll();
       
  1005 
       
  1006         // Find comma sign
       
  1007         index = ptr.Find( KCommaSign );
       
  1008         
       
  1009         if ( index == KErrNotFound )
       
  1010             {
       
  1011             // No commas found, this must be the last value
       
  1012             lex.Assign( ptr );
       
  1013             err = lex.Val( currentValue );
       
  1014             more = EFalse;
       
  1015             }
       
  1016         else
       
  1017             {
       
  1018             // Read what is to the left of the comma
       
  1019             lex.Assign( ptr.Left( index ) );
       
  1020             err = lex.Val( currentValue );
       
  1021 
       
  1022             // Delete the processed characters and the comma
       
  1023             ptr.Delete( 0, ( index + 1 ) );    
       
  1024             }
       
  1025         
       
  1026         // Get the value if conversion succeeded
       
  1027         if ( err == KErrNone )
       
  1028             {
       
  1029             error = GetBitrateMaskFromMode( currentValue,  bitrateMaskCurrent );
       
  1030             
       
  1031             //Update bitrateMask
       
  1032             if( error == KErrNone )
       
  1033                 {
       
  1034                 bitrateMaskUpdated |= bitrateMaskCurrent;
       
  1035                 }
       
  1036             //if mode not supported, then leave
       
  1037             else
       
  1038                 {
       
  1039                 User::Leave( KErrArgument );
       
  1040                 }
       
  1041                 
       
  1042             //Update max mode-set value
       
  1043             if ( currentValue > maxValue )
       
  1044                 {
       
  1045                 maxValue = currentValue;
       
  1046                 }
       
  1047             }
       
  1048         
       
  1049         // This is for the case when the last character is a comma,
       
  1050         // e.g. "mode-set=0,"
       
  1051         if ( ptr.Length() == 0 )
       
  1052             {
       
  1053             more = EFalse;
       
  1054             }
       
  1055         }
       
  1056     
       
  1057     User::LeaveIfError( err );
       
  1058 
       
  1059     // Delete the copy
       
  1060     if( hBuf )
       
  1061         {
       
  1062         CleanupStack::PopAndDestroy( hBuf );
       
  1063         hBuf = NULL;
       
  1064         }
       
  1065     
       
  1066     // Set bitrate to the maximum value found in the string
       
  1067     SetBitrateModeSet( maxValue );
       
  1068     
       
  1069     //Update the bitrateMask
       
  1070     SetBitrateMask( bitrateMaskUpdated, ETrue );
       
  1071     
       
  1072     return ETrue;
       
  1073     }
       
  1074 
       
  1075 // -----------------------------------------------------------------------------
       
  1076 // CMccCodecAMR::ParseFmtpOctetAlign
       
  1077 // Updates the CodecMode to either EOctetAligned/EBandwidthEfficient
       
  1078 // -----------------------------------------------------------------------------
       
  1079 //    
       
  1080 TBool CMccCodecAMR::ParseFmtpOctetAlignL( const TDesC8& aFmtpOctetAlign )
       
  1081     {
       
  1082     /**
       
  1083      * RFC 3267, page 39
       
  1084      *
       
  1085      * octet-align: Permissible values are 0 and 1. If 1, octet-aligned operation
       
  1086      * SHALL be used. If 0 or if not present, bandwidth efficient operation is 
       
  1087      * employed
       
  1088      */
       
  1089     
       
  1090     TBool update( ETrue );
       
  1091     
       
  1092     // Convert descriptor to integer
       
  1093     TLex8 myLex( aFmtpOctetAlign );
       
  1094     TInt octetAlign;
       
  1095     User::LeaveIfError( myLex.Val( octetAlign ) );
       
  1096     
       
  1097     switch ( octetAlign )
       
  1098         {
       
  1099         case 0:
       
  1100             SetCodecMode( EBandwidthEfficient );                
       
  1101             break;
       
  1102 
       
  1103         case 1:
       
  1104             SetCodecMode( EOctetAligned );
       
  1105             break;
       
  1106 
       
  1107         default:
       
  1108             update = EFalse;
       
  1109             break;
       
  1110         } // switch
       
  1111 
       
  1112     return update;
       
  1113     }
       
  1114 
       
  1115 // -----------------------------------------------------------------------------
       
  1116 // CMccCodecAMR::ParseFmtpModeChangePeriodL
       
  1117 // -----------------------------------------------------------------------------
       
  1118 //    
       
  1119 TBool CMccCodecAMR::ParseFmtpModeChangePeriodL( const TDesC8& aFmtpModeChangePeriod )
       
  1120     {
       
  1121     /**
       
  1122      * RFC 3267, page 39-40
       
  1123      *
       
  1124      * Specifies a number of frame-blocks, N, that is
       
  1125      * the interval at which codec mode changes are allowed.
       
  1126      * The initial phase of the interval is arbitrary, but
       
  1127      * changes must be separated by multiples of N frame-blocks.
       
  1128      * If this parameter is not present, mode changes are
       
  1129      * allowed at any time during the session.
       
  1130      */
       
  1131 
       
  1132     // Convert descriptor to integer
       
  1133     TLex8 myLex( aFmtpModeChangePeriod );
       
  1134     TInt modeChangePeriod;
       
  1135     User::LeaveIfError( myLex.Val( modeChangePeriod ) );
       
  1136 
       
  1137     User::LeaveIfError( this->SetModeChangePeriod( modeChangePeriod ) );
       
  1138      
       
  1139     return ETrue;
       
  1140     }
       
  1141     
       
  1142 // -----------------------------------------------------------------------------
       
  1143 // CMccCodecAMR::ParseFmtpModeChangeNeighborL
       
  1144 // -----------------------------------------------------------------------------
       
  1145 //    
       
  1146 TBool CMccCodecAMR::ParseFmtpModeChangeNeighborL( const TDesC8& aFmtpModeChangeNeighbor )
       
  1147     {
       
  1148     // Convert descriptor to integer
       
  1149     TLex8 myLex( aFmtpModeChangeNeighbor );
       
  1150     TInt modeChangeNeighbor;
       
  1151     User::LeaveIfError( myLex.Val( modeChangeNeighbor ) );
       
  1152    
       
  1153     User::LeaveIfError( this->SetModeChangeNeighbor( modeChangeNeighbor ) );
       
  1154                 
       
  1155     return ETrue;
       
  1156     }
       
  1157 
       
  1158 // -----------------------------------------------------------------------------
       
  1159 // CMccCodecAMR::ParseFmtpCrcL
       
  1160 // -----------------------------------------------------------------------------
       
  1161 //    
       
  1162 TBool CMccCodecAMR::ParseFmtpCrcL( const TDesC8& aFmtpCrc )
       
  1163     {
       
  1164     // Convert descriptor to integer
       
  1165     TLex8 myLex( aFmtpCrc );
       
  1166     TInt crc;
       
  1167     User::LeaveIfError( myLex.Val( crc ) );
       
  1168      
       
  1169     User::LeaveIfError( this->SetCrc( crc ) );
       
  1170                
       
  1171     return ETrue;
       
  1172     }
       
  1173     
       
  1174 // -----------------------------------------------------------------------------
       
  1175 // CMccCodecAMR::ParseFmtpRobustSortingL
       
  1176 // -----------------------------------------------------------------------------
       
  1177 //    
       
  1178 TBool CMccCodecAMR::ParseFmtpRobustSortingL( const TDesC8& aFmtpRobustSorting )
       
  1179     {
       
  1180     // Convert descriptor to integer
       
  1181     TLex8 myLex( aFmtpRobustSorting );
       
  1182     TInt robustSorting;
       
  1183     User::LeaveIfError( myLex.Val( robustSorting ) );
       
  1184   
       
  1185     User::LeaveIfError( this->SetRobustSorting( robustSorting ) );
       
  1186                 
       
  1187     return ETrue;
       
  1188     }
       
  1189         
       
  1190 // -----------------------------------------------------------------------------
       
  1191 // CMccCodecAMR::ParseFmtpInterleaving
       
  1192 // -----------------------------------------------------------------------------
       
  1193 //    
       
  1194 TBool CMccCodecAMR::ParseFmtpInterleavingL( const TDesC8& aFmtpInterleaving )
       
  1195     {  
       
  1196     // Convert descriptor to integer
       
  1197     TLex8 myLex( aFmtpInterleaving );
       
  1198     TInt interleaving;
       
  1199     User::LeaveIfError( myLex.Val( interleaving ) );
       
  1200    
       
  1201     User::LeaveIfError( this->SetInterleaving( interleaving ) );
       
  1202        
       
  1203     return ETrue;
       
  1204     } 
       
  1205 
       
  1206 // -----------------------------------------------------------------------------
       
  1207 // CMccCodecAMR::ParseFmtpMaxRedL
       
  1208 // -----------------------------------------------------------------------------
       
  1209 //    
       
  1210 TBool CMccCodecAMR::ParseFmtpMaxRedL( const TDesC8& aFmtpMaxRed )
       
  1211     {  
       
  1212     // Convert descriptor to integer
       
  1213     TLex8 myLex( aFmtpMaxRed );
       
  1214     TInt maxRed;
       
  1215     User::LeaveIfError( myLex.Val( maxRed ) );   
       
  1216     User::LeaveIfError( this->SetMaxRed( maxRed ) );
       
  1217        
       
  1218     return ETrue;
       
  1219     } 
       
  1220     
       
  1221 // -----------------------------------------------------------------------------
       
  1222 // CMccCodecAMR::CreateFmtpOctetAlign
       
  1223 // Creates the octet-alignment value of the FMTP according to the codec
       
  1224 // -----------------------------------------------------------------------------
       
  1225 //
       
  1226 TBool CMccCodecAMR::CreateFmtpOctetAlign( TDes8& aBuf )
       
  1227     {
       
  1228     TBool octetAlignAdded( EFalse );
       
  1229     // Append only if octet-aligned is EOctetAligned
       
  1230     if( CodecMode() == EOctetAligned ) 
       
  1231         {
       
  1232         TInt octetAlignValue( 1 );    
       
  1233         // Append it to the buffer        
       
  1234         _LIT8( KFmtpOctetAlign, "octet-align=%d" );
       
  1235         aBuf.AppendFormat( KFmtpOctetAlign, octetAlignValue );
       
  1236         octetAlignAdded = ETrue;
       
  1237         }
       
  1238     return octetAlignAdded;
       
  1239     }
       
  1240     
       
  1241 // -----------------------------------------------------------------------------
       
  1242 // CMccCodecAMR::CreateFmtpModeChangePeriod
       
  1243 // Creates the mode-change-period value of the FMTP according to the codec
       
  1244 // -----------------------------------------------------------------------------
       
  1245 //
       
  1246 TBool CMccCodecAMR::CreateFmtpModeChangePeriod( TDes8& aBuf )
       
  1247     {
       
  1248     TBool modeChangePeriodAdded( EFalse );
       
  1249     // No need to add to fmtp if mode-change-period=1 (default)
       
  1250     if ( iModeChangePeriod == KNumValue2 ) 
       
  1251         {  
       
  1252         // Append it to the buffer        
       
  1253         _LIT8( KFmtpModeChangePeriod, "mode-change-period=%d" );
       
  1254         aBuf.AppendFormat( KFmtpModeChangePeriod, iModeChangePeriod );
       
  1255         modeChangePeriodAdded = ETrue;       
       
  1256         }
       
  1257         
       
  1258     return modeChangePeriodAdded;    
       
  1259     }
       
  1260     
       
  1261 // -----------------------------------------------------------------------------
       
  1262 // CMccCodecAMR::CreateFmtpModeChangeNeighbor
       
  1263 // Creates the mode-change-neighbor value of the FMTP according to the codec
       
  1264 // -----------------------------------------------------------------------------
       
  1265 //
       
  1266 TBool CMccCodecAMR::CreateFmtpModeChangeNeighbor( TDes8& aBuf )
       
  1267     {
       
  1268     TBool modeChangeNeighborAdded( EFalse );
       
  1269     // Append only if mode-change-neighbor is ETrue
       
  1270     if ( iNeighbor ) 
       
  1271         {  
       
  1272         // Append it to the buffer        
       
  1273         _LIT8( KFmtpModeChangeNeighbor, "mode-change-neighbor=%d" );
       
  1274         aBuf.AppendFormat( KFmtpModeChangeNeighbor, iNeighbor );
       
  1275         modeChangeNeighborAdded = ETrue;       
       
  1276         
       
  1277         }
       
  1278         
       
  1279     return modeChangeNeighborAdded;    
       
  1280     }  
       
  1281 
       
  1282 // -----------------------------------------------------------------------------
       
  1283 // CMccCodecAMR::CreateFmtpMaxRed
       
  1284 // -----------------------------------------------------------------------------
       
  1285 //
       
  1286 TBool CMccCodecAMR::CreateFmtpMaxRed( TDes8& aBuf )
       
  1287     {
       
  1288     TBool maxRedAdded( EFalse );
       
  1289     
       
  1290     if ( KNotSet < iMaxRed && EAmrFecUsed == iAlgoUsed ) 
       
  1291         {  
       
  1292         // Append it to the buffer        
       
  1293         _LIT8( KFmtpMaxRed, "max-red=%d" );
       
  1294         aBuf.AppendFormat( KFmtpMaxRed, iMaxRed );
       
  1295         maxRedAdded = ETrue;       
       
  1296         }
       
  1297         
       
  1298     return maxRedAdded;    
       
  1299     }
       
  1300       
       
  1301 // -----------------------------------------------------------------------------
       
  1302 // CMccCodecAMR::CreateFmtpAttrListL
       
  1303 // If fmtp does not exist, then create it
       
  1304 // -----------------------------------------------------------------------------
       
  1305 //   
       
  1306 void CMccCodecAMR::CreateFmtpAttrListL()
       
  1307     {
       
  1308     RArray<TUint> array;
       
  1309     CleanupClosePushL( array );
       
  1310     
       
  1311     this->GetAllowedBitratesArrayL( array );
       
  1312     
       
  1313     this->CreateFmtpAttrListL( array );
       
  1314     
       
  1315     CleanupStack::Pop( &array );
       
  1316     array.Close();
       
  1317     }
       
  1318 
       
  1319 // -----------------------------------------------------------------------------
       
  1320 // CMccCodecAMR::CreateFmtpAttrListL
       
  1321 // If fmtp does not exist, then create it
       
  1322 // -----------------------------------------------------------------------------
       
  1323 //        
       
  1324 void CMccCodecAMR::CreateFmtpAttrListL( const RArray<TUint>& aBitrates )
       
  1325     {
       
  1326     // Create the fmtp string: octet-align=0/1; mode-set=[0][,1][,2]...[,7]
       
  1327     // mode-change-period=1/2; mode-change-neighbor=0/1
       
  1328     HBufC8* buf = HBufC8::NewLC( KMaxFmtpLen ); 
       
  1329     TPtr8 bufPtr = buf->Des();
       
  1330     
       
  1331     TBool previousParamAdded( EFalse );
       
  1332     
       
  1333     if ( CreateFmtpOctetAlign( bufPtr ) )
       
  1334         {
       
  1335         previousParamAdded = ETrue;
       
  1336         }
       
  1337     
       
  1338     TInt semicolonPos( bufPtr.Length() );
       
  1339     
       
  1340     if ( CreateFmtpModeSet( bufPtr, aBitrates ) )
       
  1341         {
       
  1342         // Previous param was added, so we need a semi-colon and a space
       
  1343         if ( previousParamAdded )
       
  1344             {
       
  1345             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
  1346             }
       
  1347         previousParamAdded = ETrue;
       
  1348         }
       
  1349     
       
  1350     semicolonPos = bufPtr.Length();
       
  1351     
       
  1352     if ( CreateFmtpModeChangePeriod( bufPtr ) )
       
  1353         {
       
  1354         // Previous param was added, so we need a semi-colon and a space
       
  1355         if ( previousParamAdded )
       
  1356             {
       
  1357             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
  1358             }
       
  1359         previousParamAdded = ETrue;
       
  1360         }
       
  1361     
       
  1362     semicolonPos = bufPtr.Length();
       
  1363         
       
  1364     if ( CreateFmtpModeChangeNeighbor( bufPtr ) )
       
  1365         {
       
  1366         // Previous param was added, so we need a semi-colon and a space
       
  1367         if ( previousParamAdded )
       
  1368             {
       
  1369             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
  1370             }
       
  1371         previousParamAdded = ETrue;
       
  1372         }
       
  1373         
       
  1374     semicolonPos = bufPtr.Length();
       
  1375         
       
  1376     if ( CreateFmtpMaxRed( bufPtr ) )
       
  1377         {
       
  1378         // Previous param was added, so we need a semi-colon and a space
       
  1379         if ( previousParamAdded )
       
  1380             {
       
  1381             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
  1382             }
       
  1383         //previousParamAdded = ETrue; not necessery if no more attributes
       
  1384         }     
       
  1385                 
       
  1386     // Remove extra space from the end
       
  1387     bufPtr.TrimRight();
       
  1388         
       
  1389     // Update iFmtpAttr
       
  1390     SetFmtpAttrL( bufPtr, EFalse );
       
  1391     
       
  1392     CleanupStack::PopAndDestroy( buf );
       
  1393     
       
  1394     __INTERFACE_STR8( "CMccCodecAMR::CreateFmtpAttrListL, *iFmtpAttr", *iFmtpAttr )
       
  1395     }    
       
  1396 
       
  1397 // -----------------------------------------------------------------------------
       
  1398 // CMccCodecAMR::SetModeChangePeriod
       
  1399 // Set mode change period
       
  1400 // -----------------------------------------------------------------------------
       
  1401 //
       
  1402 TInt CMccCodecAMR::SetModeChangePeriod( const TInt aPeriod )
       
  1403     {
       
  1404     // valid value 1 or 2
       
  1405     if( KNumValue1 > aPeriod || KNumValue2 < aPeriod )
       
  1406         {
       
  1407         return KErrArgument;
       
  1408         }
       
  1409     
       
  1410     iModeChangePeriod = aPeriod;
       
  1411     
       
  1412     SetBitrateMaskAdditionalInfo( 
       
  1413         ( iModeChangePeriod == KNumValue2 ) ? KMccAllowedModeChangePeriod2 : 0 );
       
  1414     
       
  1415     return KErrNone;
       
  1416     }
       
  1417 
       
  1418 // -----------------------------------------------------------------------------
       
  1419 // CMccCodecAMR::ModeChangePeriod
       
  1420 // Get mode change period
       
  1421 // -----------------------------------------------------------------------------
       
  1422 //
       
  1423 TInt CMccCodecAMR::ModeChangePeriod( ) const
       
  1424     {
       
  1425     return iModeChangePeriod;
       
  1426     }
       
  1427 
       
  1428 // -----------------------------------------------------------------------------
       
  1429 // CMccCodecAMR::SetModeChangeNeighbor
       
  1430 // Set mode change neighbor
       
  1431 // -----------------------------------------------------------------------------
       
  1432 //
       
  1433 TInt CMccCodecAMR::SetModeChangeNeighbor( const TBool aNeighbor )
       
  1434     {
       
  1435     // Default value is ETrue
       
  1436     iNeighbor = aNeighbor;
       
  1437     
       
  1438     SetBitrateMaskAdditionalInfo( 
       
  1439         iNeighbor ? KMccAllowedModeChangeNeighbor1 : 0 );
       
  1440     
       
  1441     return KErrNone;
       
  1442     }
       
  1443 
       
  1444 // -----------------------------------------------------------------------------
       
  1445 // CMccCodecAMR::ModeChangeNeighbor
       
  1446 // Get mode change neighbor
       
  1447 // -----------------------------------------------------------------------------
       
  1448 //
       
  1449 TBool CMccCodecAMR::ModeChangeNeighbor( ) const
       
  1450     {
       
  1451     return iNeighbor;
       
  1452     }
       
  1453 
       
  1454 // -----------------------------------------------------------------------------
       
  1455 // CMccCodecAMR::SetCrc
       
  1456 // Set boolean type CRC value
       
  1457 // -----------------------------------------------------------------------------
       
  1458 //  
       
  1459 TInt CMccCodecAMR::SetCrc( const TBool aCrc )
       
  1460     {
       
  1461     return ( aCrc ? KErrNotSupported : KErrNone );
       
  1462     }
       
  1463 
       
  1464 // -----------------------------------------------------------------------------
       
  1465 // CMccCodecAMR::GetCrc
       
  1466 // Get boolean type CRC value
       
  1467 // -----------------------------------------------------------------------------
       
  1468 // 
       
  1469 TBool CMccCodecAMR::GetCrc( ) const
       
  1470     {
       
  1471     return iCrc;
       
  1472     }
       
  1473 
       
  1474 // -----------------------------------------------------------------------------
       
  1475 // CMccCodecAMR::SetRobustSorting
       
  1476 // Default implementation
       
  1477 // -----------------------------------------------------------------------------
       
  1478 // 
       
  1479 TInt CMccCodecAMR::SetRobustSorting( const TBool aRobust )
       
  1480     {
       
  1481     return ( aRobust ? KErrNotSupported : KErrNone );
       
  1482     }
       
  1483 
       
  1484 // -----------------------------------------------------------------------------
       
  1485 // CMccCodecAMR::GetRobustSorting
       
  1486 // Default implementation
       
  1487 // -----------------------------------------------------------------------------
       
  1488 // 
       
  1489 TBool CMccCodecAMR::GetRobustSorting( ) const
       
  1490     {
       
  1491     return iRobust;
       
  1492     }
       
  1493 
       
  1494 // -----------------------------------------------------------------------------
       
  1495 // CMccCodecAMR::SetInterleaving
       
  1496 // Default implementation
       
  1497 // -----------------------------------------------------------------------------
       
  1498 // 
       
  1499 TInt CMccCodecAMR::SetInterleaving( const TInt /*aFrameBlockCount*/ )
       
  1500     {
       
  1501     return KErrNotSupported;
       
  1502     }
       
  1503 
       
  1504 // -----------------------------------------------------------------------------
       
  1505 // CMccCodecAMR:GetInterleaving
       
  1506 // Default implementation
       
  1507 // -----------------------------------------------------------------------------
       
  1508 // 
       
  1509 TInt CMccCodecAMR::GetInterleaving( ) const
       
  1510     {
       
  1511     return iFrameBlockCount;
       
  1512     }  
       
  1513 
       
  1514 // -----------------------------------------------------------------------------
       
  1515 // CMCPAMRCodec::SetChannels 
       
  1516 // -----------------------------------------------------------------------------
       
  1517 // 
       
  1518 TInt CMccCodecAMR::SetChannels( TInt aNumOfChannels )
       
  1519     {
       
  1520     if ( aNumOfChannels != 1 )
       
  1521         {
       
  1522         return KErrNotSupported;
       
  1523         }
       
  1524 
       
  1525     iNumOfChannels = aNumOfChannels;    
       
  1526     
       
  1527     return KErrNone;
       
  1528     }
       
  1529 
       
  1530 // -----------------------------------------------------------------------------
       
  1531 // CMCPAMRCodec:GetChannels
       
  1532 // -----------------------------------------------------------------------------
       
  1533 // 
       
  1534 TInt CMccCodecAMR::GetChannels( TInt& aNumOfChannels ) const
       
  1535     {   
       
  1536     aNumOfChannels = iNumOfChannels;
       
  1537     return KErrNone; 
       
  1538     }
       
  1539 
       
  1540 // -----------------------------------------------------------------------------
       
  1541 // CMccCodecAMR:SetMaxRed
       
  1542 // -----------------------------------------------------------------------------
       
  1543 // 
       
  1544 TInt CMccCodecAMR::SetMaxRed( TInt aMaxRed ) 
       
  1545     {   
       
  1546     if ( ( KNotSet > aMaxRed ) ||
       
  1547         ( aMaxRed % TInt( KDefaultPtime ) ) != 0 )
       
  1548         {
       
  1549         return KErrArgument;
       
  1550         }
       
  1551         
       
  1552     iMaxRed = aMaxRed;
       
  1553     return KErrNone;
       
  1554     }
       
  1555 
       
  1556 // -----------------------------------------------------------------------------
       
  1557 // CMccCodecAMR:SetBitrateMask
       
  1558 // -----------------------------------------------------------------------------
       
  1559 // 
       
  1560 void CMccCodecAMR::SetBitrateMask( TUint aBitrateMask, TBool aKeepAdditionalInfo )
       
  1561     {
       
  1562     __INTERFACE_INT1( "CMccCodecAMR::SetBitrateMask, entry mask ", aBitrateMask )      
       
  1563     TUint oldBitrateMask = iBitrateMask; 
       
  1564     iBitrateMask = aBitrateMask;
       
  1565         
       
  1566     if ( aKeepAdditionalInfo )
       
  1567         {
       
  1568         iBitrateMask |= ( oldBitrateMask & iAdditionalInfoMask );
       
  1569         }
       
  1570     else
       
  1571         {
       
  1572         SetBitrateMaskAdditionalInfo( aBitrateMask );
       
  1573         }
       
  1574         
       
  1575     __INTERFACE_INT1( "CMccCodecAMR::SetBitrateMask, exit mask ", iBitrateMask )      
       
  1576     }
       
  1577 
       
  1578 // -----------------------------------------------------------------------------
       
  1579 // CMccCodecAMR:SetBitrateMaskAdditionalInfo
       
  1580 // -----------------------------------------------------------------------------
       
  1581 //    
       
  1582 void CMccCodecAMR::SetBitrateMaskAdditionalInfo( TUint aAdditionalInfo )
       
  1583     {
       
  1584     iBitrateMask |= ( aAdditionalInfo & iAdditionalInfoMask );
       
  1585     }
       
  1586     
       
  1587 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  1588 
       
  1589 //  End of File