multimediacommsengine/mmcecli/src/mcedtmfcodec.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 "mcedtmfcodec.h"
       
    22 #include "mcecomdtmfcodec.h"
       
    23 #include "mcecomaudiocodec.h"
       
    24 #include "mceaudiostream.h"
       
    25 
       
    26 
       
    27 #define _FLAT_DATA static_cast<CMceComAudioCodec*>( iFlatData )
       
    28 #define FLAT_DATA( data ) _FLAT_DATA->data
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMceDtmfCodec::~CMceDtmfCodec
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C CMceDtmfCodec::~CMceDtmfCodec()
       
    37     {
       
    38     }
       
    39     
       
    40 // -----------------------------------------------------------------------------
       
    41 // CMceDtmfCodec::CloneL
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C CMceAudioCodec* CMceDtmfCodec::CloneL() const
       
    45     {
       
    46     CMceDtmfCodec* clone = CMceDtmfCodec::NewLC( FLAT_DATA( iSdpName ) );
       
    47     
       
    48     CMceComAudioCodec* cloneFlatData = 
       
    49         static_cast<CMceComAudioCodec*>( clone->iFlatData );
       
    50     
       
    51     cloneFlatData->iID = FLAT_DATA( iID );
       
    52     cloneFlatData->SetFmtpAttributeL( *(FLAT_DATA( iFmtpAttr )) );
       
    53 	cloneFlatData->iSamplingFreq = FLAT_DATA( iSamplingFreq );
       
    54 	cloneFlatData->iPTime = FLAT_DATA( iPTime );
       
    55 	cloneFlatData->iPayloadType = FLAT_DATA( iPayloadType );
       
    56 	cloneFlatData->iCodecMode = FLAT_DATA( iCodecMode );
       
    57 	cloneFlatData->iFourCC = FLAT_DATA( iFourCC );
       
    58 	
       
    59 	CleanupStack::Pop( clone );
       
    60 	
       
    61 	return clone;
       
    62     }
       
    63     
       
    64 // -----------------------------------------------------------------------------
       
    65 // CMceDtmfCodec::EnableVAD
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C TInt CMceDtmfCodec::EnableVAD( TBool /*aEnableVAD*/ )
       
    69     {
       
    70     return KErrNotSupported;
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CMceDtmfCodec::SetBitrate
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C TInt CMceDtmfCodec::SetBitrate( TUint /*aBitrate*/ )
       
    78     {
       
    79     return KErrNotSupported;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CMceDtmfCodec::SetAllowedBitrates
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C TInt CMceDtmfCodec::SetAllowedBitrates( TUint aBitrates )
       
    87     {
       
    88     if ( aBitrates != AllowedBitrates() )
       
    89         {
       
    90         TInt ret = _FLAT_DATA->SetAllowedBitrates( aBitrates );
       
    91         if ( ret == KErrNone )
       
    92             {
       
    93             CMceAudioStream* stream = static_cast< CMceAudioStream* >( iStream );
       
    94             if ( stream && stream->BoundStream() )
       
    95                 {
       
    96                 // Find the same codec in bound stream, and set bitrate also to that. 
       
    97                 CMceCodec* codec = stream->Bound()->FindCodec( *this );
       
    98                 if ( codec )
       
    99                     {
       
   100                     ret = codec->SetAllowedBitrates( aBitrates );
       
   101                     }
       
   102                 }
       
   103             }
       
   104         return ret;
       
   105         }
       
   106     else
       
   107         {
       
   108         // Avoid looping, go here if already set
       
   109         return KErrNone;
       
   110         }
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CMceDtmfCodec::SetSamplingFreq
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C TInt CMceDtmfCodec::SetSamplingFreq( TUint aSamplingFreq )
       
   118     {
       
   119     return _FLAT_DATA->SetSamplingFreq( aSamplingFreq );
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CMceDtmfCodec::SetPTime
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C TInt CMceDtmfCodec::SetPTime( TUint aPTime )
       
   128     {
       
   129     return _FLAT_DATA->SetPTime( aPTime );
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CMceDtmfCodec::SetMaxPTime
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C TInt CMceDtmfCodec::SetMaxPTime( TUint /*aMaxPTime*/ )
       
   137     {
       
   138     return KErrNotSupported;
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMceDtmfCodec::SetPayloadType
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 EXPORT_C TInt CMceDtmfCodec::SetPayloadType( TUint8 aPayloadType )
       
   146     {
       
   147     return _FLAT_DATA->SetPayloadType( aPayloadType );
       
   148     }
       
   149     
       
   150 // -----------------------------------------------------------------------------
       
   151 // CMceDtmfCodec::SetCodecMode
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C TInt CMceDtmfCodec::SetCodecMode( TUint aCodecMode )
       
   155     {
       
   156     if ( aCodecMode != CodecMode() )
       
   157         {
       
   158         TInt ret = _FLAT_DATA->SetCodecMode( aCodecMode );
       
   159         if ( KErrNone == ret )
       
   160             {
       
   161             CMceAudioStream* stream = static_cast< CMceAudioStream* >( iStream );
       
   162             if ( stream && stream->BoundStream() )
       
   163                 {
       
   164                 // Find the same codec in bound stream, and set mode also to that.
       
   165                 CMceCodec* codec = stream->Bound()->FindCodec( *this );
       
   166                 if ( codec )
       
   167                     {
       
   168                     ret = codec->SetCodecMode( aCodecMode );
       
   169                     }
       
   170                 }
       
   171             }
       
   172         
       
   173         return ret;
       
   174         }
       
   175     else
       
   176         {
       
   177         // Avoid looping, go here if already set
       
   178         return KErrNone;
       
   179         }
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CMceDtmfCodec::NewL
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 CMceDtmfCodec* CMceDtmfCodec::NewL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   188     {
       
   189     CMceDtmfCodec* self = NewLC( aSdpName );
       
   190     CleanupStack::Pop( self );
       
   191     return self;
       
   192     
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CMceDtmfCodec::NewL
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 CMceDtmfCodec* CMceDtmfCodec::NewLC( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   200     {
       
   201     CMceDtmfCodec* self = new (ELeave) CMceDtmfCodec();
       
   202     CleanupStack::PushL( self );
       
   203     self->ConstructL( aSdpName );
       
   204     return self;
       
   205     
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CMceDtmfCodec::CMceDtmfCodec
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 CMceDtmfCodec::CMceDtmfCodec()
       
   213  : CMceAudioCodec()
       
   214     {
       
   215     }
       
   216 
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CMceDtmfCodec::ConstructL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CMceDtmfCodec::ConstructL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   223     {
       
   224     CMceComAudioCodec* codec = CMceComDtmfCodec::NewLC( aSdpName );
       
   225     CMceAudioCodec::ConstructL( codec );
       
   226 	
       
   227     CleanupStack::Pop( codec );
       
   228     }
       
   229 
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CMceDtmfCodec::SetSdpNameL
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CMceDtmfCodec::SetSdpNameL( const TDesC8& aSdpName )
       
   236     {
       
   237     __ASSERT_ALWAYS( aSdpName.Length() <= KMceMaxSdpNameLength, 
       
   238                      User::Leave( KErrArgument ) );
       
   239     FLAT_DATA( iSdpName ).Copy( aSdpName );
       
   240     }
       
   241