multimediacommscontroller/mmccinterface/src/mmcccodecg711.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004-2006 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 G.711 CodecInformation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "mmcccodecg711.h"
       
    23 #include "mccuids.hrh"
       
    24 #include "mmccinterfacelogs.h"
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 const TUint8 KG711KAPayloadSize = 160;
       
    29 const TUint8 KG711KeepAlivePayload[KG711KAPayloadSize] = 
       
    30     { 
       
    31     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    32     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    33     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    34     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    35     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    36     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    37     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    38     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    39     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    40     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    41     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    42     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    43     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    44     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    45     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
       
    46     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
       
    47     };
       
    48 
       
    49 const TInt KG711SampleRate = 8000;
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CMCCCodecG711::CMCCCodecG711
       
    54 // default constructor
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CMCCCodecG711::CMCCCodecG711() : CMccCodecInformation()
       
    58     {   
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CMCCCodecG711::ConstructL
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CMCCCodecG711::ConstructL()
       
    67     {
       
    68     __INTERFACE( "CMCCCodecG711::ConstructL" )
       
    69     
       
    70     iKeepAliveData.Copy( KG711KeepAlivePayload,  KMaxKeepAliveDataLen);    
       
    71     SetSamplingFreq( KG711SampleRate );
       
    72     SetBitrate( KG711Bitrate64 );
       
    73     EnableVAD( EFalse );
       
    74     iHwFrameTime = KG711DefaultHwFrameTime; // default 20ms
       
    75     SetMaxPTime( KMaxPtime );
       
    76     SetPTime( KDefaultPtime );
       
    77     SetPayloadType( KPcmuPayloadType );
       
    78     SetSdpName( KPCMUSdpName );
       
    79     SetCodecMode( EPCMU );
       
    80     
       
    81     iFourCC = KMccFourCCIdG711;
       
    82     iPayloadFormatEncoder = KImplUidG711PayloadFormatEncode;
       
    83     iPayloadFormatDecoder = KImplUidG711PayloadFormatDecode;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMCCCodecG711::NewL
       
    88 // Static constructor.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CMCCCodecG711* CMCCCodecG711::NewL()
       
    92     {
       
    93     CMCCCodecG711* self = new (ELeave) CMCCCodecG711;
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL();
       
    96     CleanupStack::Pop( self ); 
       
    97     return self;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CMCCCodecG711::~CMCCCodecG711
       
   102 // Destructor
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CMCCCodecG711::~CMCCCodecG711()
       
   106     {
       
   107     __INTERFACE( "CMCCCodecG711::~CMCCCodecG711" )
       
   108     }
       
   109     
       
   110 // -----------------------------------------------------------------------------
       
   111 // CMCCCodecG711::EnableVAD
       
   112 // Enable / Disable VAD
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 TInt CMCCCodecG711::EnableVAD( TBool aEnableVAD )
       
   116     {
       
   117     iEnableVAD = aEnableVAD;
       
   118     return KErrNone;
       
   119     }
       
   120 
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMCCCodecG711::SetBitrate
       
   124 // Set Bitrate
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 TInt CMCCCodecG711::SetBitrate( TUint aBitrate )
       
   128     {
       
   129     if ( KG711Bitrate64 != aBitrate )
       
   130         {
       
   131         return KErrNotSupported;
       
   132         }
       
   133     else
       
   134         {
       
   135         iBitrate = aBitrate;
       
   136         return KErrNone;
       
   137         }
       
   138     }
       
   139 
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMCCCodecG711::SetSamplingFreq
       
   143 // Set Sampling Frequency
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 TInt CMCCCodecG711::SetSamplingFreq( TUint32 aSamplingFreq )
       
   147     {
       
   148     if ( KG711SampleRate == aSamplingFreq )
       
   149         {
       
   150         iSamplingFreq = aSamplingFreq;
       
   151         return KErrNone;
       
   152         }
       
   153     else
       
   154         {
       
   155         return KErrNotSupported;
       
   156         }
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CMCCCodecG711::SetSdpName
       
   161 // Set SDP Name
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 TInt CMCCCodecG711::SetSdpName( const TDesC8& aSdpName )
       
   165     {
       
   166     if ( !aSdpName.CompareF( KPCMUSdpName ) )
       
   167         {
       
   168         iSdpName.Copy( aSdpName );
       
   169         SetCodecMode( EPCMU );
       
   170         }
       
   171     else if ( !aSdpName.CompareF( KPCMASdpName ) )
       
   172         {
       
   173         iSdpName.Copy( aSdpName );
       
   174         SetCodecMode( EPCMA );
       
   175         }
       
   176     else 
       
   177         {
       
   178         return KErrNotSupported;        
       
   179         }
       
   180         
       
   181     return KErrNone;
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CMCCCodecG711::SetPayloadType
       
   186 // Set PayloadType
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 TInt CMCCCodecG711::SetPayloadType( TUint8 aType )
       
   190     {
       
   191     if ( KPcmuPayloadType != aType && KPcmaPayloadType != aType ) 
       
   192         {
       
   193         return KErrNotSupported;
       
   194         }
       
   195     else 
       
   196         {
       
   197         iPayloadType = aType;
       
   198         }
       
   199     
       
   200     return KErrNone;
       
   201     }
       
   202  
       
   203 // -----------------------------------------------------------------------------
       
   204 // CMCCCodecG711::SetPTime
       
   205 // Set PTime
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 TInt CMCCCodecG711::SetPTime( TUint aPTime )
       
   209     {
       
   210     if ( aPTime && ( KMinPtime <= aPTime ) && ( aPTime <= iMaxPTime ) && 
       
   211         ( KMaxPtime >= aPTime ) && (( aPTime % KMinPtime ) == 0 ))
       
   212         {
       
   213         iPTime = aPTime;
       
   214         return KErrNone;    
       
   215         }
       
   216     else
       
   217         {
       
   218         return KErrArgument;
       
   219         }
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CMCCCodecG711::SetMaxPTime
       
   224 // Set Max PTime
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 TInt CMCCCodecG711::SetMaxPTime( TUint aMaxPTime )
       
   228     {
       
   229     if ( aMaxPTime && ( iPTime <= aMaxPTime ) && ( KMinPtime <= aMaxPTime ) &&
       
   230         ( KMaxPtime >= aMaxPTime ) && (( aMaxPTime % KMinPtime ) == 0 ))
       
   231         {
       
   232         iMaxPTime = aMaxPTime;
       
   233         return KErrNone;    
       
   234         }
       
   235     else
       
   236         {
       
   237         return KErrArgument;
       
   238         }
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CMCCCodecG711::SetCodecMode
       
   243 // Set Codec Mode
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 TInt CMCCCodecG711::SetCodecMode( TCodecMode aCodecMode )
       
   247     {
       
   248     if ( EPCMU == aCodecMode )
       
   249         {
       
   250         iCodecMode = aCodecMode;
       
   251         iSdpName.Copy( KPCMUSdpName );
       
   252         SetPayloadType( KG711PayloadTypePCMU );
       
   253         return KErrNone;
       
   254         }
       
   255     else if ( EPCMA == aCodecMode )
       
   256         {
       
   257         iCodecMode = aCodecMode;
       
   258         iSdpName.Copy( KPCMASdpName );            
       
   259         SetPayloadType( KG711PayloadTypePCMA );  
       
   260         return KErrNone;
       
   261         }
       
   262     else
       
   263         {
       
   264         return KErrNotSupported;
       
   265         }
       
   266     }
       
   267     
       
   268 // -----------------------------------------------------------------------------
       
   269 // CMCCCodecG711::CloneDefaultsL
       
   270 // Make a default setting clone from this G.711 codec
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 CMccCodecInformation* CMCCCodecG711::CloneDefaultsL()
       
   274     {
       
   275     CMccCodecInformation* codec = CMCCCodecG711::NewL();
       
   276     CleanupStack::PushL( codec );
       
   277     
       
   278     if ( 0 == this->SdpName().CompareF( KPCMASdpName ) )
       
   279         {
       
   280         User::LeaveIfError( codec->SetCodecMode( EPCMA ) );
       
   281         }
       
   282     else
       
   283         {
       
   284         User::LeaveIfError( codec->SetCodecMode( EPCMU ) );
       
   285         }
       
   286     
       
   287     CleanupStack::Pop( codec );
       
   288     return codec;
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CMCCCodecG711::CloneDetailedL
       
   293 // Make a detailed clone from this G.711 codec
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 CMccCodecInformation* CMCCCodecG711::CloneDetailedL()
       
   297     {
       
   298     CMCCCodecG711* newCodec = CMCCCodecG711::NewL();
       
   299     CleanupStack::PushL( newCodec );    
       
   300     newCodec->SetBitrate( this->Bitrate() );
       
   301     newCodec->SetCodecMode( this->CodecMode() );
       
   302     newCodec->SetMaxPTime( this->MaxPTime() );
       
   303     newCodec->SetPayloadType( this->PayloadType() );
       
   304     newCodec->SetPTime( this->PTime() );
       
   305     newCodec->SetSamplingFreq( this->SamplingFreq() );
       
   306     newCodec->SetSdpName( this->SdpName() );
       
   307     CleanupStack::Pop( newCodec );    
       
   308     return newCodec;
       
   309     }
       
   310     
       
   311 // -----------------------------------------------------------------------------
       
   312 // CMCCCodecG711::RequireSignalling
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 TBool CMCCCodecG711::RequireSignalling(
       
   316     const CMccCodecInformation& aCandidate ) const      
       
   317     {
       
   318     __INTERFACE( "CMCCCodecG711::RequireSignalling" )
       
   319     TBool ret = EFalse;
       
   320               
       
   321     if ( iPTime != aCandidate.PTime() )
       
   322         {
       
   323         __INTERFACE( "CMCCCodecG711::RequireSignalling, PTime changed" )
       
   324         ret = ETrue;
       
   325         }
       
   326         
       
   327     if ( iMaxPTime != aCandidate.MaxPTime() )
       
   328         {
       
   329         __INTERFACE( "CMCCCodecG711::RequireSignalling, MaxPTime changed" )
       
   330         ret = ETrue;
       
   331         }
       
   332         
       
   333     if ( iPayloadType != aCandidate.PayloadType() )
       
   334         {
       
   335         __INTERFACE( "CMCCCodecG711::RequireSignalling, PayloadType changed" )
       
   336         ret = ETrue;
       
   337         }
       
   338         
       
   339     __INTERFACE_INT1( "CMCCCodecG711::RequireSignalling, exit with", ret )
       
   340     return ret;          
       
   341     }
       
   342         
       
   343 // -----------------------------------------------------------------------------
       
   344 // CMCPG711Codec::SetComfortNoiseGeneration
       
   345 // -----------------------------------------------------------------------------
       
   346 // 
       
   347 TInt CMCCCodecG711::SetComfortNoiseGeneration( TUint8 aComfortNoisePT )
       
   348     {
       
   349     iComfortNoiseGenerationPt = aComfortNoisePT;
       
   350     return KErrNone;
       
   351     }
       
   352     
       
   353 // -----------------------------------------------------------------------------
       
   354 // CMCCCodecG711::SetAllowedBitrates
       
   355 // -----------------------------------------------------------------------------
       
   356 // 
       
   357 TInt CMCCCodecG711::SetAllowedBitrates( TUint /*aBitrateMask*/ )
       
   358     {
       
   359     return KErrNone;           
       
   360     }
       
   361         
       
   362 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   363 
       
   364 //  End of File