multimediacommsengine/mmceshared/src/mcecomamrwbcodec.cpp
changeset 0 1bce908db942
child 13 fb1bbf85a302
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mceamrcodec.h"
       
    22 #include "mceamrwbcodec.h"
       
    23 #include "mcecomamrwbcodec.h"
       
    24 
       
    25 #ifdef MCE_COMMON_SERVER_SIDE
       
    26 
       
    27 #include <mmcccodecinformation.h>
       
    28 
       
    29 _LIT8( KDefaultAmrWbFmtp, "octet-align=0; mode-set=0,1,2,3,4,5,6,7,8" );
       
    30 
       
    31 #endif//MCE_COMMON_SERVER_SIDE
       
    32 
       
    33 // This should be defined in MCE API
       
    34 const TUint KMceAmrWBFrameSize ( 64 );
       
    35 
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CMceComAMRWbCodec::NewL
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CMceComAMRWbCodec* CMceComAMRWbCodec::NewL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    44     {
       
    45     CMceComAMRWbCodec* self = NewLC( aSdpName );
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMceComAMRWbCodec::NewLC
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CMceComAMRWbCodec* CMceComAMRWbCodec::NewLC( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    55     {
       
    56     CMceComAMRWbCodec* self = new (ELeave) CMceComAMRWbCodec();
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aSdpName );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CMceComAMRWbCodec::~CMceComAMRWbCodec
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CMceComAMRWbCodec::~CMceComAMRWbCodec()
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMceComAMRWbCodec::CMceComAMRWbCodec
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CMceComAMRWbCodec::CMceComAMRWbCodec()
       
    75  : CMceComAMRCodec()
       
    76     {
       
    77     iCodecMode = EMceBandwidthEfficient;    
       
    78     iBitrate = KMceAmrWbBitrate2385;	
       
    79    	iAllowedBitrates = KMceAllowedAmrWbBitrate660|
       
    80 					   KMceAllowedAmrWbBitrate885|
       
    81 					   KMceAllowedAmrWbBitrate1265|
       
    82 					   KMceAllowedAmrWbBitrate1425|
       
    83 					   KMceAllowedAmrWbBitrate1585|
       
    84 					   KMceAllowedAmrWbBitrate1825|
       
    85 					   KMceAllowedAmrWbBitrate1985|
       
    86 					   KMceAllowedAmrWbBitrate2305|
       
    87 					   KMceAllowedAmrWbBitrate2385;
       
    88 	//Above codec mode need to have value as 8
       
    89     iFrameSize = KMceAmrWBFrameSize;
       
    90    	const TUint8 KDefaultAmrWbPayloadType = 100;
       
    91 	iPayloadType = KDefaultAmrWbPayloadType;
       
    92 	iSamplingFreq = KMceAmrWbSamplingFreq;
       
    93 	iPTime = KMceDefaultPtime;
       
    94 	iMaxPTime = KMceDefaultMaxPtime;
       
    95     }
       
    96 
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CMceComAMRWbCodec::CloneL
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CMceComAudioCodec* CMceComAMRWbCodec::CloneL()
       
   103     {
       
   104     CMceComAMRWbCodec* copy = new (ELeave) CMceComAMRWbCodec();
       
   105     CleanupStack::PushL( copy );
       
   106     copy->ConstructL( *this );
       
   107     CleanupStack::Pop( copy );
       
   108     return copy;
       
   109     
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CMceComAMRWbCodec::SetBitrate
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt CMceComAMRWbCodec::SetBitrate( TUint aBitrate )
       
   117     {
       
   118 	TBool isValid = ETrue;
       
   119 	
       
   120     switch ( aBitrate )
       
   121     	{
       
   122     	case KMceAmrWbBitrate660:
       
   123 		case KMceAmrWbBitrate885:
       
   124 		case KMceAmrWbBitrate1265:
       
   125 		case KMceAmrWbBitrate1425:
       
   126 		case KMceAmrWbBitrate1585:
       
   127 		case KMceAmrWbBitrate1825:
       
   128 		case KMceAmrWbBitrate1985:
       
   129 		case KMceAmrWbBitrate2305:
       
   130 		case KMceAmrWbBitrate2385:
       
   131     	    {
       
   132     	    if ( aBitrate > GetMaxBitRate() )
       
   133     	        {
       
   134         		isValid = EFalse;
       
   135     	        }
       
   136     	    break;
       
   137     	    }
       
   138     	default:
       
   139     		isValid = EFalse;
       
   140     		break;
       
   141     	}
       
   142     	
       
   143     if ( isValid )
       
   144     	{
       
   145         return CMceComCodec::SetBitrate( aBitrate );
       
   146     	}
       
   147     else
       
   148     	{
       
   149     	return KErrNotSupported;
       
   150     	}
       
   151     
       
   152     }
       
   153     
       
   154 // -----------------------------------------------------------------------------
       
   155 // CMceComAMRWbCodec::SetAllowedBitrates
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 TInt CMceComAMRWbCodec::SetAllowedBitrates( TUint aBitrates )
       
   159     {
       
   160     TInt error = KErrNone;
       
   161         
       
   162     //Confirm that the bitrate mask is valid
       
   163     //I.e. after all the valid bitrates are set to zero the value should be zero
       
   164     if ( !aBitrates || 
       
   165         ( aBitrates >> 16 ) > 0 ) 
       
   166         {
       
   167         error = KErrArgument;
       
   168         }
       
   169     else
       
   170         {
       
   171         CMceComCodec::SetAllowedBitrates( KMceAllowedAmrWbBitrateAll );
       
   172         iAllowedBitrates &= aBitrates;
       
   173         TUint maxBitrate = GetMaxBitRate();
       
   174         if ( iBitrate > maxBitrate )
       
   175             {
       
   176             error = CMceComCodec::SetBitrate( maxBitrate );
       
   177             } 
       
   178             
       
   179         // Update also other amr codec information stored inside
       
   180         iAllowedBitrates |= ( aBitrates & KMceAllowedAmrWbAdditionalInfo );
       
   181         }
       
   182     
       
   183     return error;
       
   184     
       
   185     }
       
   186     
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CMceComAMRWbCodec::GetMaxBitRate
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 TUint CMceComAMRWbCodec::GetMaxBitRate()
       
   193 	{
       
   194 	
       
   195     if( iAllowedBitrates & KMceAllowedAmrWbBitrate2385 )
       
   196         {
       
   197         return KMceAmrWbBitrate2385;
       
   198         }
       
   199     else if( iAllowedBitrates & KMceAllowedAmrWbBitrate2305 )
       
   200         {
       
   201         return KMceAmrWbBitrate2305;
       
   202         }
       
   203     else if( iAllowedBitrates & KMceAllowedAmrWbBitrate1985 )
       
   204         {
       
   205         return KMceAmrWbBitrate1985;
       
   206         }   
       
   207     else if( iAllowedBitrates & KMceAllowedAmrWbBitrate1825 )
       
   208         {
       
   209         return KMceAmrWbBitrate1825;
       
   210         }   
       
   211     else if( iAllowedBitrates & KMceAllowedAmrWbBitrate1585 )
       
   212         {
       
   213         return KMceAmrWbBitrate1585;
       
   214         }   
       
   215     else if( iAllowedBitrates & KMceAllowedAmrWbBitrate1425 )
       
   216         {
       
   217         return KMceAmrWbBitrate1425;
       
   218         }
       
   219     else if( iAllowedBitrates & KMceAllowedAmrWbBitrate1265 )
       
   220         {
       
   221         return KMceAmrWbBitrate1265;
       
   222         }  
       
   223     else if( iAllowedBitrates & KMceAllowedAmrWbBitrate885 )
       
   224         {
       
   225         return KMceAmrWbBitrate885;
       
   226         }
       
   227     else if( iAllowedBitrates & KMceAllowedAmrWbBitrate660 )
       
   228         {
       
   229         return KMceAmrWbBitrate660;
       
   230         }
       
   231         
       
   232     else
       
   233         {
       
   234         return 0;    
       
   235         }
       
   236 
       
   237 	}
       
   238 	
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CMceComAMRWbCodec::ResolveAllowedBitrates
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 TInt CMceComAMRWbCodec::ResolveAllowedBitrates( 
       
   245     TUint aBitrate, TUint& aAllowedBitrates )
       
   246     {
       
   247     TInt retVal( KErrNone );
       
   248     
       
   249     if ( aBitrate <= KMceAmrWbBitrate660 )
       
   250         {
       
   251         aAllowedBitrates = KMceAllowedAmrWbBitrate660;
       
   252         }
       
   253     else if ( aBitrate <= KMceAmrWbBitrate885 )
       
   254         {
       
   255         aAllowedBitrates = KMceAllowedAmrWbBitrate885;
       
   256         }
       
   257     else if ( aBitrate <= KMceAmrWbBitrate1265 )
       
   258         {
       
   259         aAllowedBitrates = KMceAllowedAmrWbBitrate1265;
       
   260         }
       
   261     else if ( aBitrate <= KMceAmrWbBitrate1425 )
       
   262         {
       
   263         aAllowedBitrates = KMceAllowedAmrWbBitrate1425;
       
   264         }
       
   265     else if ( aBitrate <= KMceAmrWbBitrate1585 )
       
   266         {
       
   267         aAllowedBitrates = KMceAllowedAmrWbBitrate1585;
       
   268         }
       
   269     else if ( aBitrate <= KMceAmrWbBitrate1825 )
       
   270         {
       
   271         aAllowedBitrates = KMceAllowedAmrWbBitrate1825;
       
   272         }
       
   273     else if ( aBitrate <= KMceAmrWbBitrate1985 )
       
   274         {
       
   275         aAllowedBitrates = KMceAllowedAmrWbBitrate1985;
       
   276         }
       
   277     else if ( aBitrate <= KMceAmrWbBitrate2305 )
       
   278         {
       
   279         aAllowedBitrates = KMceAllowedAmrWbBitrate2305;
       
   280         }
       
   281     else if ( aBitrate <= KMceAmrWbBitrate2385 )
       
   282         {
       
   283         aAllowedBitrates = KMceAllowedAmrWbBitrateAll;
       
   284         }
       
   285     else
       
   286         {
       
   287         retVal = KErrNotSupported;
       
   288         }
       
   289     
       
   290     return retVal;
       
   291     }
       
   292 
       
   293 
       
   294 
       
   295 #ifdef MCE_COMMON_SERVER_SIDE
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CMceComAMRWbCodec::DoMccValidateL
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 CMceComCodec* CMceComAMRWbCodec::DoMccValidateL( CMccCodecInformation& aMccCodec,
       
   302                                                CMceSrvStream& /*aStream*/,
       
   303                                                TMceNegotiationRole aRole )
       
   304     {
       
   305     //if answerer mcc codec represents the received offer and codec the answer
       
   306     //if offerer codec represents the sent offer and mcc codec the answer
       
   307     
       
   308     // Bitrates field contains also additional information, mask it away
       
   309     TUint mccBitrates = ( aMccCodec.AllowedBitrates() & KMceAllowedAmrWbBitrateAll );
       
   310     TUint mceBitrates = ( iAllowedBitrates & KMceAllowedAmrWbBitrateAll );
       
   311     
       
   312     TBool notValid = aRole == EMceRoleAnswerer ?
       
   313                   ( mceBitrates && mccBitrates == 0 ||
       
   314 	                mceBitrates > mccBitrates ) :
       
   315                   ( mceBitrates && mccBitrates == 0 ||
       
   316 	                mceBitrates < mccBitrates );
       
   317 	
       
   318 	User::LeaveIfError( notValid ? KErrNotSupported : KErrNone );
       
   319 	if ( aMccCodec.CodecMode() != (TCodecMode)iCodecMode )
       
   320 		{
       
   321 		// codec-mode was different, fail.
       
   322 		User::Leave(KErrNotSupported);
       
   323 		}
       
   324 	return NULL;
       
   325     }
       
   326 
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CMceComAMRWbCodec::DoSetDefaultFmtpAttributeL
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CMceComAMRWbCodec::DoSetDefaultFmtpAttributeL()
       
   333     {
       
   334     SetFmtpAttributeL( KDefaultAmrWbFmtp );   
       
   335     }
       
   336     
       
   337 #endif
       
   338 
       
   339 
       
   340 // End of File
       
   341