multimediacommsengine/tsrc/mccstub/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     return CMccCodecInformation::RequireSignalling( aCandidate );
       
   776     }
       
   777  
       
   778 // -----------------------------------------------------------------------------
       
   779 // CMccCodecAMR::ParseFmtpAttrL
       
   780 // Parse the fmtp string, but doesn't update the iFmtpAttr
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 TBool CMccCodecAMR::ParseFmtpAttrL( const TDesC8& aFmtp )
       
   784     {
       
   785     // These booleans needed in FMTP parsing to handle where parameters
       
   786     // not present in FMTP
       
   787 
       
   788     iModesExist = EFalse;
       
   789     iOctetAlignExist = EFalse;
       
   790     iModeChangePeriodExist = EFalse;
       
   791     iModeChangeNeighborExist = EFalse;
       
   792     iMaxRedExist = EFalse;
       
   793     
       
   794     //Remove all white space from begining and end,
       
   795     //Convert the content of the descriptor to lower case
       
   796     const TUint8* pointerC = aFmtp.Ptr();
       
   797     TUint8* pointer        = const_cast<TUint8*>( pointerC );
       
   798     TPtr8 descriptor( pointer, aFmtp.Length(), aFmtp.Length() );
       
   799     descriptor.Trim();
       
   800     
       
   801     /*
       
   802     TDelimitedPathSegmentParser8 Parses path segments whose 
       
   803     components are delimited by the ';' character, 
       
   804     as defined in RFC2396.
       
   805     */
       
   806     TDelimitedPathSegmentParser8 parser;
       
   807     parser.Parse( aFmtp );
       
   808     TPtrC8 segment;
       
   809     TBool updated( EFalse );
       
   810     
       
   811     while ( parser.GetNext( segment ) != KErrNotFound )
       
   812         {
       
   813         if ( ParseFmtpSegmentL( segment ) )
       
   814             {
       
   815             updated = ETrue;
       
   816             }
       
   817         }
       
   818     
       
   819     if ( !iModesExist )
       
   820         {
       
   821         // Allow all modes
       
   822         SetBitrateMask( iDefaultBitrateMask, ETrue );
       
   823         SetBitrate( iDefaultBitrate ); // max bitrate
       
   824         }
       
   825         
       
   826     if ( !iOctetAlignExist )
       
   827         {
       
   828         SetCodecMode( EBandwidthEfficient );
       
   829         }
       
   830     
       
   831     if ( !iModeChangePeriodExist )
       
   832         {
       
   833         SetModeChangePeriod( KDefaultModeChangePeriod );
       
   834         }
       
   835         
       
   836     if ( !iModeChangeNeighborExist )
       
   837         {
       
   838         SetModeChangeNeighbor( EFalse );
       
   839         }
       
   840         
       
   841     if ( !iMaxRedExist )
       
   842         {
       
   843         SetMaxRed( KNotSet );
       
   844         }   
       
   845                 
       
   846     return updated;
       
   847     }
       
   848 
       
   849 // -----------------------------------------------------------------------------
       
   850 // CMccCodecAMR::ParseFmtpSegmentL
       
   851 // Parse and updates the matched param
       
   852 // -----------------------------------------------------------------------------
       
   853 //    
       
   854 TBool CMccCodecAMR::ParseFmtpSegmentL( const TDesC8& aSeg )
       
   855     {
       
   856     TBool update( EFalse );
       
   857     _LIT8( KEqualSign, "=" );
       
   858     
       
   859     // Check for first '=' sign 
       
   860     TInt index = aSeg.Find( KEqualSign );
       
   861     
       
   862     if ( index > 0 )
       
   863         {
       
   864         // Check if match mode-set 
       
   865         if ( aSeg.Left( index ).Match( KMatchModeSet  ) != KErrNotFound )
       
   866             {
       
   867             update = ParseFmtpModeSetL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   868             iModesExist = ETrue;
       
   869             }      
       
   870         // Check if match octet-align
       
   871         else if ( aSeg.Left( index ).Match( KMatchOctetAlign ) != KErrNotFound )
       
   872             {
       
   873             update = ParseFmtpOctetAlignL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   874             iOctetAlignExist = ETrue;
       
   875             }
       
   876 
       
   877         // Check if match mode-change-period
       
   878         else if ( aSeg.Left( index ).Match( KMatchModeChangePeriod ) != KErrNotFound )
       
   879             {
       
   880             update = ParseFmtpModeChangePeriodL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   881             iModeChangePeriodExist = ETrue;
       
   882             }
       
   883         // Check if match mode-change-neighbor
       
   884         else if ( aSeg.Left( index ).Match( KMatchModeChangeNeighbor ) != KErrNotFound )
       
   885             {
       
   886             update = ParseFmtpModeChangeNeighborL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   887             iModeChangeNeighborExist = ETrue;
       
   888             }
       
   889         // Check if match crc
       
   890         else if ( aSeg.Left( index ).Match( KCrc ) != KErrNotFound )
       
   891             {
       
   892             update = ParseFmtpCrcL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   893             }
       
   894         // Check if match crc
       
   895         else if ( aSeg.Left( index ).Match( KRobustSorting ) != KErrNotFound )
       
   896             {
       
   897             update = ParseFmtpRobustSortingL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   898             }
       
   899         // Check if match interleaving
       
   900         else if ( aSeg.Left( index ).Match( KInterleaving ) != KErrNotFound )
       
   901             {
       
   902             update = ParseFmtpInterleavingL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   903             }
       
   904         else if ( aSeg.Left( index ).Match( KMaxRed ) != KErrNotFound )
       
   905             {
       
   906             update = ParseFmtpMaxRedL( aSeg.Right( aSeg.Length() - ( index + 1 ) ) );
       
   907             }              
       
   908         else
       
   909             {
       
   910             // Make PC-LINT happy.
       
   911             }
       
   912         }
       
   913   
       
   914     return update;
       
   915     }
       
   916 
       
   917 // -----------------------------------------------------------------------------
       
   918 // CMccCodecAMR::ParseFmtpModeSet
       
   919 // Parses and updates the bitrate
       
   920 // -----------------------------------------------------------------------------
       
   921 //      
       
   922 TBool CMccCodecAMR::ParseFmtpModeSetL( const TDesC8& aFmtpModeSet )
       
   923     {
       
   924     /**
       
   925      * RFC 3267, page 39
       
   926      *
       
   927      * mode-set: Requested AMR mode set. Restricts the active codec mode 
       
   928      * set to a subset of all modes. Possible values are a comma separetad
       
   929      * list of modes from the set: 0,..,7. If such mode set is specified by 
       
   930      * the decoder, the encoder MUST abide by the request and  MUST NOT use
       
   931      * modes outside of the subset. If not present, all codec modes are 
       
   932      * allowed for the session
       
   933      **/
       
   934      
       
   935     TInt err( KErrNone );
       
   936     TInt error( KErrNone );
       
   937     
       
   938     HBufC8* hBuf = HBufC8::NewLC( aFmtpModeSet.Length() );
       
   939 
       
   940     hBuf->Des().Copy( aFmtpModeSet );
       
   941     TPtr8 ptr( hBuf->Des() );
       
   942 
       
   943     // Convert descriptor to integer using TLex8
       
   944     TLex8 lex;
       
   945     TInt index( KErrNone );
       
   946     TInt maxValue( 0 );
       
   947     TInt currentValue( 0 );
       
   948     
       
   949     TUint bitrateMaskCurrent( 0 );
       
   950     TUint bitrateMaskUpdated( 0 );
       
   951     
       
   952     TBool more( ETrue );
       
   953     
       
   954     while ( more )
       
   955         {
       
   956         ptr.TrimAll();
       
   957 
       
   958         // Find comma sign
       
   959         index = ptr.Find( KCommaSign );
       
   960         
       
   961         if ( index == KErrNotFound )
       
   962             {
       
   963             // No commas found, this must be the last value
       
   964             lex.Assign( ptr );
       
   965             err = lex.Val( currentValue );
       
   966             more = EFalse;
       
   967             }
       
   968         else
       
   969             {
       
   970             // Read what is to the left of the comma
       
   971             lex.Assign( ptr.Left( index ) );
       
   972             err = lex.Val( currentValue );
       
   973 
       
   974             // Delete the processed characters and the comma
       
   975             ptr.Delete( 0, ( index + 1 ) );    
       
   976             }
       
   977         
       
   978         // Get the value if conversion succeeded
       
   979         if ( err == KErrNone )
       
   980             {
       
   981             error = GetBitrateMaskFromMode( currentValue,  bitrateMaskCurrent );
       
   982             
       
   983             //Update bitrateMask
       
   984             if( error == KErrNone )
       
   985                 {
       
   986                 bitrateMaskUpdated |= bitrateMaskCurrent;
       
   987                 }
       
   988             //if mode not supported, then leave
       
   989             else
       
   990                 {
       
   991                 User::Leave( KErrArgument );
       
   992                 }
       
   993                 
       
   994             //Update max mode-set value
       
   995             if ( currentValue > maxValue )
       
   996                 {
       
   997                 maxValue = currentValue;
       
   998                 }
       
   999             }
       
  1000         
       
  1001         // This is for the case when the last character is a comma,
       
  1002         // e.g. "mode-set=0,"
       
  1003         if ( ptr.Length() == 0 )
       
  1004             {
       
  1005             more = EFalse;
       
  1006             }
       
  1007         }
       
  1008     
       
  1009     User::LeaveIfError( err );
       
  1010 
       
  1011     // Delete the copy
       
  1012     if( hBuf )
       
  1013         {
       
  1014         CleanupStack::PopAndDestroy( hBuf );
       
  1015         hBuf = NULL;
       
  1016         }
       
  1017     
       
  1018     // Set bitrate to the maximum value found in the string
       
  1019     SetBitrateModeSet( maxValue );
       
  1020     
       
  1021     //Update the bitrateMask
       
  1022     SetBitrateMask( bitrateMaskUpdated, ETrue );
       
  1023     
       
  1024     return ETrue;
       
  1025     }
       
  1026 
       
  1027 // -----------------------------------------------------------------------------
       
  1028 // CMccCodecAMR::ParseFmtpOctetAlign
       
  1029 // Updates the CodecMode to either EOctetAligned/EBandwidthEfficient
       
  1030 // -----------------------------------------------------------------------------
       
  1031 //    
       
  1032 TBool CMccCodecAMR::ParseFmtpOctetAlignL( const TDesC8& aFmtpOctetAlign )
       
  1033     {
       
  1034     /**
       
  1035      * RFC 3267, page 39
       
  1036      *
       
  1037      * octet-align: Permissible values are 0 and 1. If 1, octet-aligned operation
       
  1038      * SHALL be used. If 0 or if not present, bandwidth efficient operation is 
       
  1039      * employed
       
  1040      */
       
  1041     
       
  1042     TBool update( ETrue );
       
  1043     
       
  1044     // Convert descriptor to integer
       
  1045     TLex8 myLex( aFmtpOctetAlign );
       
  1046     TInt octetAlign;
       
  1047     User::LeaveIfError( myLex.Val( octetAlign ) );
       
  1048     
       
  1049     switch ( octetAlign )
       
  1050         {
       
  1051         case 0:
       
  1052             SetCodecMode( EBandwidthEfficient );                
       
  1053             break;
       
  1054 
       
  1055         case 1:
       
  1056             SetCodecMode( EOctetAligned );
       
  1057             break;
       
  1058 
       
  1059         default:
       
  1060             update = EFalse;
       
  1061             break;
       
  1062         } // switch
       
  1063 
       
  1064     return update;
       
  1065     }
       
  1066 
       
  1067 // -----------------------------------------------------------------------------
       
  1068 // CMccCodecAMR::ParseFmtpModeChangePeriodL
       
  1069 // -----------------------------------------------------------------------------
       
  1070 //    
       
  1071 TBool CMccCodecAMR::ParseFmtpModeChangePeriodL( const TDesC8& aFmtpModeChangePeriod )
       
  1072     {
       
  1073     /**
       
  1074      * RFC 3267, page 39-40
       
  1075      *
       
  1076      * Specifies a number of frame-blocks, N, that is
       
  1077      * the interval at which codec mode changes are allowed.
       
  1078      * The initial phase of the interval is arbitrary, but
       
  1079      * changes must be separated by multiples of N frame-blocks.
       
  1080      * If this parameter is not present, mode changes are
       
  1081      * allowed at any time during the session.
       
  1082      */
       
  1083 
       
  1084     // Convert descriptor to integer
       
  1085     TLex8 myLex( aFmtpModeChangePeriod );
       
  1086     TInt modeChangePeriod;
       
  1087     User::LeaveIfError( myLex.Val( modeChangePeriod ) );
       
  1088 
       
  1089     User::LeaveIfError( this->SetModeChangePeriod( modeChangePeriod ) );
       
  1090      
       
  1091     return ETrue;
       
  1092     }
       
  1093     
       
  1094 // -----------------------------------------------------------------------------
       
  1095 // CMccCodecAMR::ParseFmtpModeChangeNeighborL
       
  1096 // -----------------------------------------------------------------------------
       
  1097 //    
       
  1098 TBool CMccCodecAMR::ParseFmtpModeChangeNeighborL( const TDesC8& aFmtpModeChangeNeighbor )
       
  1099     {
       
  1100     // Convert descriptor to integer
       
  1101     TLex8 myLex( aFmtpModeChangeNeighbor );
       
  1102     TInt modeChangeNeighbor;
       
  1103     User::LeaveIfError( myLex.Val( modeChangeNeighbor ) );
       
  1104    
       
  1105     User::LeaveIfError( this->SetModeChangeNeighbor( modeChangeNeighbor ) );
       
  1106                 
       
  1107     return ETrue;
       
  1108     }
       
  1109 
       
  1110 // -----------------------------------------------------------------------------
       
  1111 // CMccCodecAMR::ParseFmtpCrcL
       
  1112 // -----------------------------------------------------------------------------
       
  1113 //    
       
  1114 TBool CMccCodecAMR::ParseFmtpCrcL( const TDesC8& aFmtpCrc )
       
  1115     {
       
  1116     // Convert descriptor to integer
       
  1117     TLex8 myLex( aFmtpCrc );
       
  1118     TInt crc;
       
  1119     User::LeaveIfError( myLex.Val( crc ) );
       
  1120      
       
  1121     User::LeaveIfError( this->SetCrc( crc ) );
       
  1122                
       
  1123     return ETrue;
       
  1124     }
       
  1125     
       
  1126 // -----------------------------------------------------------------------------
       
  1127 // CMccCodecAMR::ParseFmtpRobustSortingL
       
  1128 // -----------------------------------------------------------------------------
       
  1129 //    
       
  1130 TBool CMccCodecAMR::ParseFmtpRobustSortingL( const TDesC8& aFmtpRobustSorting )
       
  1131     {
       
  1132     // Convert descriptor to integer
       
  1133     TLex8 myLex( aFmtpRobustSorting );
       
  1134     TInt robustSorting;
       
  1135     User::LeaveIfError( myLex.Val( robustSorting ) );
       
  1136   
       
  1137     User::LeaveIfError( this->SetRobustSorting( robustSorting ) );
       
  1138                 
       
  1139     return ETrue;
       
  1140     }
       
  1141         
       
  1142 // -----------------------------------------------------------------------------
       
  1143 // CMccCodecAMR::ParseFmtpInterleaving
       
  1144 // -----------------------------------------------------------------------------
       
  1145 //    
       
  1146 TBool CMccCodecAMR::ParseFmtpInterleavingL( const TDesC8& aFmtpInterleaving )
       
  1147     {  
       
  1148     // Convert descriptor to integer
       
  1149     TLex8 myLex( aFmtpInterleaving );
       
  1150     TInt interleaving;
       
  1151     User::LeaveIfError( myLex.Val( interleaving ) );
       
  1152    
       
  1153     User::LeaveIfError( this->SetInterleaving( interleaving ) );
       
  1154        
       
  1155     return ETrue;
       
  1156     } 
       
  1157 
       
  1158 // -----------------------------------------------------------------------------
       
  1159 // CMccCodecAMR::ParseFmtpMaxRedL
       
  1160 // -----------------------------------------------------------------------------
       
  1161 //    
       
  1162 TBool CMccCodecAMR::ParseFmtpMaxRedL( const TDesC8& aFmtpMaxRed )
       
  1163     {  
       
  1164     // Convert descriptor to integer
       
  1165     TLex8 myLex( aFmtpMaxRed );
       
  1166     TInt maxRed;
       
  1167     User::LeaveIfError( myLex.Val( maxRed ) );   
       
  1168     User::LeaveIfError( this->SetMaxRed( maxRed ) );
       
  1169        
       
  1170     return ETrue;
       
  1171     } 
       
  1172     
       
  1173 // -----------------------------------------------------------------------------
       
  1174 // CMccCodecAMR::CreateFmtpOctetAlign
       
  1175 // Creates the octet-alignment value of the FMTP according to the codec
       
  1176 // -----------------------------------------------------------------------------
       
  1177 //
       
  1178 TBool CMccCodecAMR::CreateFmtpOctetAlign( TDes8& aBuf )
       
  1179     {
       
  1180     TBool octetAlignAdded( EFalse );
       
  1181     // Append only if octet-aligned is EOctetAligned
       
  1182     if( CodecMode() == EOctetAligned ) 
       
  1183         {
       
  1184         TInt octetAlignValue( 1 );    
       
  1185         // Append it to the buffer        
       
  1186         _LIT8( KFmtpOctetAlign, "octet-align=%d" );
       
  1187         aBuf.AppendFormat( KFmtpOctetAlign, octetAlignValue );
       
  1188         octetAlignAdded = ETrue;
       
  1189         }
       
  1190     return octetAlignAdded;
       
  1191     }
       
  1192     
       
  1193 // -----------------------------------------------------------------------------
       
  1194 // CMccCodecAMR::CreateFmtpModeChangePeriod
       
  1195 // Creates the mode-change-period value of the FMTP according to the codec
       
  1196 // -----------------------------------------------------------------------------
       
  1197 //
       
  1198 TBool CMccCodecAMR::CreateFmtpModeChangePeriod( TDes8& aBuf )
       
  1199     {
       
  1200     TBool modeChangePeriodAdded( EFalse );
       
  1201     // No need to add to fmtp if mode-change-period=1 (default)
       
  1202     if ( iModeChangePeriod == KNumValue2 ) 
       
  1203         {  
       
  1204         // Append it to the buffer        
       
  1205         _LIT8( KFmtpModeChangePeriod, "mode-change-period=%d" );
       
  1206         aBuf.AppendFormat( KFmtpModeChangePeriod, iModeChangePeriod );
       
  1207         modeChangePeriodAdded = ETrue;       
       
  1208         }
       
  1209         
       
  1210     return modeChangePeriodAdded;    
       
  1211     }
       
  1212     
       
  1213 // -----------------------------------------------------------------------------
       
  1214 // CMccCodecAMR::CreateFmtpModeChangeNeighbor
       
  1215 // Creates the mode-change-neighbor value of the FMTP according to the codec
       
  1216 // -----------------------------------------------------------------------------
       
  1217 //
       
  1218 TBool CMccCodecAMR::CreateFmtpModeChangeNeighbor( TDes8& aBuf )
       
  1219     {
       
  1220     TBool modeChangeNeighborAdded( EFalse );
       
  1221     // Append only if mode-change-neighbor is ETrue
       
  1222     if ( iNeighbor ) 
       
  1223         {  
       
  1224         // Append it to the buffer        
       
  1225         _LIT8( KFmtpModeChangeNeighbor, "mode-change-neighbor=%d" );
       
  1226         aBuf.AppendFormat( KFmtpModeChangeNeighbor, iNeighbor );
       
  1227         modeChangeNeighborAdded = ETrue;       
       
  1228         
       
  1229         }
       
  1230         
       
  1231     return modeChangeNeighborAdded;    
       
  1232     }  
       
  1233 
       
  1234 // -----------------------------------------------------------------------------
       
  1235 // CMccCodecAMR::CreateFmtpMaxRed
       
  1236 // -----------------------------------------------------------------------------
       
  1237 //
       
  1238 TBool CMccCodecAMR::CreateFmtpMaxRed( TDes8& aBuf )
       
  1239     {
       
  1240     TBool maxRedAdded( EFalse );
       
  1241     
       
  1242     if ( KNotSet < iMaxRed && EAmrFecUsed == iAlgoUsed ) 
       
  1243         {  
       
  1244         // Append it to the buffer        
       
  1245         _LIT8( KFmtpMaxRed, "max-red=%d" );
       
  1246         aBuf.AppendFormat( KFmtpMaxRed, iMaxRed );
       
  1247         maxRedAdded = ETrue;       
       
  1248         }
       
  1249         
       
  1250     return maxRedAdded;    
       
  1251     }
       
  1252       
       
  1253 // -----------------------------------------------------------------------------
       
  1254 // CMccCodecAMR::CreateFmtpAttrListL
       
  1255 // If fmtp does not exist, then create it
       
  1256 // -----------------------------------------------------------------------------
       
  1257 //   
       
  1258 void CMccCodecAMR::CreateFmtpAttrListL()
       
  1259     {
       
  1260     RArray<TUint> array;
       
  1261     CleanupClosePushL( array );
       
  1262     
       
  1263     this->GetAllowedBitratesArrayL( array );
       
  1264     
       
  1265     this->CreateFmtpAttrListL( array );
       
  1266     
       
  1267     CleanupStack::Pop( &array );
       
  1268     array.Close();
       
  1269     }
       
  1270 
       
  1271 // -----------------------------------------------------------------------------
       
  1272 // CMccCodecAMR::CreateFmtpAttrListL
       
  1273 // If fmtp does not exist, then create it
       
  1274 // -----------------------------------------------------------------------------
       
  1275 //        
       
  1276 void CMccCodecAMR::CreateFmtpAttrListL( const RArray<TUint>& aBitrates )
       
  1277     {
       
  1278     // Create the fmtp string: octet-align=0/1; mode-set=[0][,1][,2]...[,7]
       
  1279     // mode-change-period=1/2; mode-change-neighbor=0/1
       
  1280     HBufC8* buf = HBufC8::NewLC( KMaxFmtpLen ); 
       
  1281     TPtr8 bufPtr = buf->Des();
       
  1282     
       
  1283     TBool previousParamAdded( EFalse );
       
  1284     
       
  1285     if ( CreateFmtpOctetAlign( bufPtr ) )
       
  1286         {
       
  1287         previousParamAdded = ETrue;
       
  1288         }
       
  1289     
       
  1290     TInt semicolonPos( bufPtr.Length() );
       
  1291     
       
  1292     if ( CreateFmtpModeSet( bufPtr, aBitrates ) )
       
  1293         {
       
  1294         // Previous param was added, so we need a semi-colon and a space
       
  1295         if ( previousParamAdded )
       
  1296             {
       
  1297             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
  1298             }
       
  1299         previousParamAdded = ETrue;
       
  1300         }
       
  1301     
       
  1302     semicolonPos = bufPtr.Length();
       
  1303     
       
  1304     if ( CreateFmtpModeChangePeriod( bufPtr ) )
       
  1305         {
       
  1306         // Previous param was added, so we need a semi-colon and a space
       
  1307         if ( previousParamAdded )
       
  1308             {
       
  1309             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
  1310             }
       
  1311         previousParamAdded = ETrue;
       
  1312         }
       
  1313     
       
  1314     semicolonPos = bufPtr.Length();
       
  1315         
       
  1316     if ( CreateFmtpModeChangeNeighbor( bufPtr ) )
       
  1317         {
       
  1318         // Previous param was added, so we need a semi-colon and a space
       
  1319         if ( previousParamAdded )
       
  1320             {
       
  1321             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
  1322             }
       
  1323         previousParamAdded = ETrue;
       
  1324         }
       
  1325         
       
  1326     semicolonPos = bufPtr.Length();
       
  1327         
       
  1328     if ( CreateFmtpMaxRed( bufPtr ) )
       
  1329         {
       
  1330         // Previous param was added, so we need a semi-colon and a space
       
  1331         if ( previousParamAdded )
       
  1332             {
       
  1333             bufPtr.Insert( semicolonPos, KSemicolonSpace );
       
  1334             }
       
  1335         //previousParamAdded = ETrue; not necessery if no more attributes
       
  1336         }     
       
  1337                 
       
  1338     // Remove extra space from the end
       
  1339     bufPtr.TrimRight();
       
  1340         
       
  1341     // Update iFmtpAttr
       
  1342     SetFmtpAttrL( bufPtr, EFalse );
       
  1343     
       
  1344     CleanupStack::PopAndDestroy( buf );
       
  1345     
       
  1346     __INTERFACE_STR8( "CMccCodecAMR::CreateFmtpAttrListL, *iFmtpAttr", *iFmtpAttr )
       
  1347     }    
       
  1348 
       
  1349 // -----------------------------------------------------------------------------
       
  1350 // CMccCodecAMR::SetModeChangePeriod
       
  1351 // Set mode change period
       
  1352 // -----------------------------------------------------------------------------
       
  1353 //
       
  1354 TInt CMccCodecAMR::SetModeChangePeriod( const TInt aPeriod )
       
  1355     {
       
  1356     // valid value 1 or 2
       
  1357     if( KNumValue1 > aPeriod || KNumValue2 < aPeriod )
       
  1358         {
       
  1359         return KErrArgument;
       
  1360         }
       
  1361     
       
  1362     iModeChangePeriod = aPeriod;
       
  1363     
       
  1364     SetBitrateMaskAdditionalInfo( 
       
  1365         ( iModeChangePeriod == KNumValue2 ) ? KMccAllowedModeChangePeriod2 : 0 );
       
  1366     
       
  1367     return KErrNone;
       
  1368     }
       
  1369 
       
  1370 // -----------------------------------------------------------------------------
       
  1371 // CMccCodecAMR::ModeChangePeriod
       
  1372 // Get mode change period
       
  1373 // -----------------------------------------------------------------------------
       
  1374 //
       
  1375 TInt CMccCodecAMR::ModeChangePeriod( ) const
       
  1376     {
       
  1377     return iModeChangePeriod;
       
  1378     }
       
  1379 
       
  1380 // -----------------------------------------------------------------------------
       
  1381 // CMccCodecAMR::SetModeChangeNeighbor
       
  1382 // Set mode change neighbor
       
  1383 // -----------------------------------------------------------------------------
       
  1384 //
       
  1385 TInt CMccCodecAMR::SetModeChangeNeighbor( const TBool aNeighbor )
       
  1386     {
       
  1387     // Default value is ETrue
       
  1388     iNeighbor = aNeighbor;
       
  1389     
       
  1390     SetBitrateMaskAdditionalInfo( 
       
  1391         iNeighbor ? KMccAllowedModeChangeNeighbor1 : 0 );
       
  1392     
       
  1393     return KErrNone;
       
  1394     }
       
  1395 
       
  1396 // -----------------------------------------------------------------------------
       
  1397 // CMccCodecAMR::ModeChangeNeighbor
       
  1398 // Get mode change neighbor
       
  1399 // -----------------------------------------------------------------------------
       
  1400 //
       
  1401 TBool CMccCodecAMR::ModeChangeNeighbor( ) const
       
  1402     {
       
  1403     return iNeighbor;
       
  1404     }
       
  1405 
       
  1406 // -----------------------------------------------------------------------------
       
  1407 // CMccCodecAMR::SetCrc
       
  1408 // Set boolean type CRC value
       
  1409 // -----------------------------------------------------------------------------
       
  1410 //  
       
  1411 TInt CMccCodecAMR::SetCrc( const TBool aCrc )
       
  1412     {
       
  1413     return ( aCrc ? KErrNotSupported : KErrNone );
       
  1414     }
       
  1415 
       
  1416 // -----------------------------------------------------------------------------
       
  1417 // CMccCodecAMR::GetCrc
       
  1418 // Get boolean type CRC value
       
  1419 // -----------------------------------------------------------------------------
       
  1420 // 
       
  1421 TBool CMccCodecAMR::GetCrc( ) const
       
  1422     {
       
  1423     return iCrc;
       
  1424     }
       
  1425 
       
  1426 // -----------------------------------------------------------------------------
       
  1427 // CMccCodecAMR::SetRobustSorting
       
  1428 // Default implementation
       
  1429 // -----------------------------------------------------------------------------
       
  1430 // 
       
  1431 TInt CMccCodecAMR::SetRobustSorting( const TBool aRobust )
       
  1432     {
       
  1433     return ( aRobust ? KErrNotSupported : KErrNone );
       
  1434     }
       
  1435 
       
  1436 // -----------------------------------------------------------------------------
       
  1437 // CMccCodecAMR::GetRobustSorting
       
  1438 // Default implementation
       
  1439 // -----------------------------------------------------------------------------
       
  1440 // 
       
  1441 TBool CMccCodecAMR::GetRobustSorting( ) const
       
  1442     {
       
  1443     return iRobust;
       
  1444     }
       
  1445 
       
  1446 // -----------------------------------------------------------------------------
       
  1447 // CMccCodecAMR::SetInterleaving
       
  1448 // Default implementation
       
  1449 // -----------------------------------------------------------------------------
       
  1450 // 
       
  1451 TInt CMccCodecAMR::SetInterleaving( const TInt /*aFrameBlockCount*/ )
       
  1452     {
       
  1453     return KErrNotSupported;
       
  1454     }
       
  1455 
       
  1456 // -----------------------------------------------------------------------------
       
  1457 // CMccCodecAMR:GetInterleaving
       
  1458 // Default implementation
       
  1459 // -----------------------------------------------------------------------------
       
  1460 // 
       
  1461 TInt CMccCodecAMR::GetInterleaving( ) const
       
  1462     {
       
  1463     return iFrameBlockCount;
       
  1464     }  
       
  1465 
       
  1466 // -----------------------------------------------------------------------------
       
  1467 // CMCPAMRCodec::SetChannels 
       
  1468 // -----------------------------------------------------------------------------
       
  1469 // 
       
  1470 TInt CMccCodecAMR::SetChannels( TInt aNumOfChannels )
       
  1471     {
       
  1472     if ( aNumOfChannels != 1 )
       
  1473         {
       
  1474         return KErrNotSupported;
       
  1475         }
       
  1476 
       
  1477     iNumOfChannels = aNumOfChannels;    
       
  1478     
       
  1479     return KErrNone;
       
  1480     }
       
  1481 
       
  1482 // -----------------------------------------------------------------------------
       
  1483 // CMCPAMRCodec:GetChannels
       
  1484 // -----------------------------------------------------------------------------
       
  1485 // 
       
  1486 TInt CMccCodecAMR::GetChannels( TInt& aNumOfChannels ) const
       
  1487     {   
       
  1488     aNumOfChannels = iNumOfChannels;
       
  1489     return KErrNone; 
       
  1490     }
       
  1491 
       
  1492 // -----------------------------------------------------------------------------
       
  1493 // CMccCodecAMR:SetMaxRed
       
  1494 // -----------------------------------------------------------------------------
       
  1495 // 
       
  1496 TInt CMccCodecAMR::SetMaxRed( TInt aMaxRed ) 
       
  1497     {   
       
  1498     if ( ( KNotSet > aMaxRed ) ||
       
  1499         ( aMaxRed % TInt( KDefaultPtime ) ) != 0 )
       
  1500         {
       
  1501         return KErrArgument;
       
  1502         }
       
  1503         
       
  1504     iMaxRed = aMaxRed;
       
  1505     return KErrNone;
       
  1506     }
       
  1507 
       
  1508 // -----------------------------------------------------------------------------
       
  1509 // CMccCodecAMR:SetBitrateMask
       
  1510 // -----------------------------------------------------------------------------
       
  1511 // 
       
  1512 void CMccCodecAMR::SetBitrateMask( TUint aBitrateMask, TBool aKeepAdditionalInfo )
       
  1513     {
       
  1514     __INTERFACE_INT1( "CMccCodecAMR::SetBitrateMask, entry mask ", aBitrateMask )      
       
  1515     TUint oldBitrateMask = iBitrateMask; 
       
  1516     iBitrateMask = aBitrateMask;
       
  1517         
       
  1518     if ( aKeepAdditionalInfo )
       
  1519         {
       
  1520         iBitrateMask |= ( oldBitrateMask & iAdditionalInfoMask );
       
  1521         }
       
  1522     else
       
  1523         {
       
  1524         SetBitrateMaskAdditionalInfo( aBitrateMask );
       
  1525         }
       
  1526         
       
  1527     __INTERFACE_INT1( "CMccCodecAMR::SetBitrateMask, exit mask ", iBitrateMask )      
       
  1528     }
       
  1529 
       
  1530 // -----------------------------------------------------------------------------
       
  1531 // CMccCodecAMR:SetBitrateMaskAdditionalInfo
       
  1532 // -----------------------------------------------------------------------------
       
  1533 //    
       
  1534 void CMccCodecAMR::SetBitrateMaskAdditionalInfo( TUint aAdditionalInfo )
       
  1535     {
       
  1536     iBitrateMask |= ( aAdditionalInfo & iAdditionalInfoMask );
       
  1537     }
       
  1538     
       
  1539 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  1540 
       
  1541 //  End of File