multimediacommsengine/mmceshared/src/mcecomg711codec.cpp
changeset 0 1bce908db942
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 "mceg711codec.h"
       
    22 #include "mcecomg711codec.h"
       
    23 
       
    24 #ifdef MCE_COMMON_SERVER_SIDE
       
    25 
       
    26 #include <mmcccodecinformation.h>
       
    27 
       
    28 #endif //MCE_COMMON_SERVER_SIDE
       
    29 
       
    30 //G.711 Default Frame Size    
       
    31 const TUint KMceG711FrameSize = 10; 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CMceComG711Codec::NewL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMceComG711Codec* CMceComG711Codec::NewL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    42     {
       
    43     CMceComG711Codec* self = NewLC( aSdpName );
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CMceComG711Codec::NewLC
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CMceComG711Codec* CMceComG711Codec::NewLC( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    54     {
       
    55     CMceComG711Codec* self = new (ELeave) CMceComG711Codec();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL( aSdpName );
       
    58     return self;
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CMceComG711Codec::~CMceComG711Codec
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CMceComG711Codec::~CMceComG711Codec()
       
    67     {
       
    68     }
       
    69     
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CMceComG711Codec::CMceComG711Codec
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CMceComG711Codec::CMceComG711Codec()
       
    76  : CMceComAudioCodec()
       
    77     {
       
    78     iFourCC = 0;
       
    79     iEnableVAD = EFalse;
       
    80 	iSamplingFreq  = KMceG711SamplingFreq;
       
    81 	iBitrate  = KMceG711Bitrate64;
       
    82 	iPTime = KMceG711DefaultPtime;
       
    83 	iMaxPTime = KMceG711DefaultMaxPtime;
       
    84 	iAllowedBitrates = KMceAllowedG711Bitrate64K;
       
    85 	iPayloadType = KMcePCMAPayloadType;
       
    86 	iCodecMode = KMceG711PCMA;    
       
    87     iFrameSize = KMceG711FrameSize;
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CMceComG711Codec::CloneL
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CMceComAudioCodec* CMceComG711Codec::CloneL()
       
    96     {
       
    97     CMceComG711Codec* copy = new (ELeave) CMceComG711Codec();
       
    98     CleanupStack::PushL( copy );
       
    99     copy->ConstructL( *this );
       
   100     CleanupStack::Pop( copy );
       
   101     return copy;
       
   102     
       
   103     }
       
   104 
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CMceComG711Codec::ConstructL
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CMceComG711Codec::ConstructL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   111     {
       
   112     
       
   113     CMceComAudioCodec::ConstructL( aSdpName );
       
   114     
       
   115     if( !iSdpName.CompareF(KMceSDPNamePCMU) )
       
   116         {
       
   117         iCodecMode = KMceG711PCMU; 
       
   118         iPayloadType = KMcePCMUPayloadType;
       
   119         }
       
   120     else
       
   121         {
       
   122         iCodecMode = KMceG711PCMA;
       
   123         iPayloadType = KMcePCMAPayloadType;
       
   124         }
       
   125     
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CMceComG711Codec::ConstructL
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CMceComG711Codec::ConstructL( CMceComG711Codec& aCodec )
       
   133     {
       
   134     CMceComAudioCodec::ConstructL( aCodec );
       
   135     }
       
   136 
       
   137 
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CMceComG711Codec::SetBitrate
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TInt CMceComG711Codec::SetBitrate( TUint aBitrate )
       
   144     {
       
   145 	
       
   146     TBool isValid = ETrue;
       
   147 	
       
   148     switch ( aBitrate )
       
   149     	{
       
   150     	case KMceG711Bitrate64:
       
   151     	    {
       
   152     	    if ( aBitrate > GetMaxBitRate() )
       
   153     	        {
       
   154         		isValid = EFalse;
       
   155     	        }
       
   156     	    break;
       
   157     	    }
       
   158     	default:
       
   159     		isValid = EFalse;
       
   160     		break;
       
   161     	}
       
   162     	
       
   163     if ( isValid )
       
   164     	{
       
   165         return CMceComCodec::SetBitrate( aBitrate );
       
   166     	}
       
   167     else
       
   168     	{
       
   169     	return KErrNotSupported;
       
   170     	}
       
   171     }
       
   172    
       
   173    
       
   174 // -----------------------------------------------------------------------------
       
   175 // CMceComG711Codec::SetAllowedBitrates
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 TInt CMceComG711Codec::SetAllowedBitrates( TUint aBitrates )
       
   179     {
       
   180     TInt error = KErrNone;
       
   181     
       
   182     //Confirm that the bitrate mask is valid
       
   183     //I.e. after all the valid bitrates are set to zero the value should be zero
       
   184     if ( !aBitrates || 
       
   185         ( aBitrates >> 8 ) > 0 ) 
       
   186         {
       
   187         error = KErrArgument;
       
   188         }
       
   189     else
       
   190         {
       
   191         CMceComCodec::SetAllowedBitrates( KMceAllowedG711BitrateAllowAll );
       
   192         iAllowedBitrates &= aBitrates;
       
   193         TUint maxBitrate = GetMaxBitRate();
       
   194         if ( iBitrate > maxBitrate )
       
   195             {
       
   196             error = CMceComCodec::SetBitrate( maxBitrate );
       
   197             }
       
   198         }
       
   199     
       
   200     return error;
       
   201     
       
   202     }
       
   203 
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CMceComG711Codec::SetCodecMode
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TInt CMceComG711Codec::SetCodecMode( TUint aCodecMode )
       
   210     {
       
   211     if ( KMceG711PCMU == aCodecMode || KMceG711PCMA == aCodecMode )
       
   212         {
       
   213         iCodecMode = aCodecMode;
       
   214         return KErrNone;
       
   215         }
       
   216     else
       
   217         {
       
   218         return KErrNotSupported;
       
   219         }
       
   220     }
       
   221 
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CMceComG711Codec::GetMaxBitRate
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 TUint CMceComG711Codec::GetMaxBitRate()
       
   228 	{
       
   229     if( iAllowedBitrates & KMceAllowedG711Bitrate64K )
       
   230         {
       
   231         return KMceG711Bitrate64;
       
   232         }
       
   233     else
       
   234         {
       
   235         return 0;    
       
   236         }
       
   237     }   
       
   238     
       
   239 // -----------------------------------------------------------------------------
       
   240 // CMceComG711Codec::SetPTime
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 TInt CMceComG711Codec::SetPTime( TUint aPTime )
       
   244     {
       
   245     if ( ( aPTime % KMceG711FrameSize ) == 0 )
       
   246         {
       
   247         return CMceComAudioCodec::SetPTime( aPTime );
       
   248         }
       
   249     else
       
   250         {
       
   251         return KErrNotSupported;
       
   252         }
       
   253     }
       
   254 
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CMceComG711Codec::SetMaxPTime
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TInt CMceComG711Codec::SetMaxPTime( TUint aMaxPTime )
       
   261     {
       
   262     if ( ( aMaxPTime % KMceG711FrameSize ) == 0 )
       
   263         {
       
   264         return CMceComAudioCodec::SetMaxPTime( aMaxPTime );
       
   265         }
       
   266     else
       
   267         {
       
   268         return KErrNotSupported;
       
   269         }
       
   270     }
       
   271 
       
   272 // End of File