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