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