multimediacommsengine/mmceshared/src/mcecomdtmfcodec.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 
       
    24 #ifdef MCE_COMMON_SERVER_SIDE
       
    25 
       
    26 #include <mmcccodecinformation.h>
       
    27 #include "mcecomaudiostream.h"
       
    28 #include "mcertpsink.h"
       
    29 #include "mcertpsource.h"
       
    30 #include "mcemmlogs.h"
       
    31 
       
    32 #endif //MCE_COMMON_SERVER_SIDE
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CMceComDtmfCodec::NewL
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CMceComDtmfCodec* CMceComDtmfCodec::NewL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    43     {
       
    44     CMceComDtmfCodec* self = NewLC( aSdpName );
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMceComDtmfCodec::NewLC
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CMceComDtmfCodec* CMceComDtmfCodec::NewLC( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
    55     {
       
    56     CMceComDtmfCodec* self = new (ELeave) CMceComDtmfCodec();
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aSdpName );
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CMceComDtmfCodec::~CMceComDtmfCodec
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CMceComDtmfCodec::~CMceComDtmfCodec()
       
    68     {
       
    69     }
       
    70     
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CMceComDtmfCodec::CMceComDtmfCodec
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CMceComDtmfCodec::CMceComDtmfCodec()
       
    77  : CMceComAudioCodec()
       
    78     {
       
    79     iFourCC = 0;
       
    80     iEnableVAD = EFalse;
       
    81 	iSamplingFreq  = KMceDtmfSamplingFreq;
       
    82 	iPTime = KMceDtmfDefaultPtime;
       
    83     const TUint KMceDtmfDefaultMaxPtime = 200;
       
    84 	iMaxPTime = KMceDtmfDefaultMaxPtime;
       
    85 	iAllowedBitrates = KMceAllowedDtmfEvents0to15;
       
    86 	iPayloadType = KMceDefaultDtmfPayloadType;
       
    87     iCodecMode = EMceOutbound;
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CMceComDtmfCodec::CloneL
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CMceComAudioCodec* CMceComDtmfCodec::CloneL()
       
    96     {
       
    97     CMceComDtmfCodec* copy = new (ELeave) CMceComDtmfCodec();
       
    98     CleanupStack::PushL( copy );
       
    99     copy->ConstructL( *this );
       
   100     CleanupStack::Pop( copy );
       
   101     return copy;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CMceComDtmfCodec::ConstructL
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CMceComDtmfCodec::ConstructL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   109     {
       
   110     CMceComAudioCodec::ConstructL( aSdpName );
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CMceComDtmfCodec::ConstructL
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CMceComDtmfCodec::ConstructL( CMceComDtmfCodec& aCodec )
       
   118     {
       
   119     CMceComAudioCodec::ConstructL( aCodec );
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMceComDtmfCodec::SetBitrate
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 TInt CMceComDtmfCodec::SetBitrate( TUint /*aBitrate*/ )
       
   127     {
       
   128 	return KErrNotSupported;
       
   129     }  
       
   130    
       
   131 // -----------------------------------------------------------------------------
       
   132 // CMceComDtmfCodec::SetAllowedBitrates
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 TInt CMceComDtmfCodec::SetAllowedBitrates( TUint aBitrates )
       
   136     {
       
   137     // Nothing else is supported at the moment
       
   138     if( !( aBitrates == KMceAllowedDtmfEvents0to15 ) )
       
   139     	{
       
   140     	return KErrArgument;
       
   141     	}
       
   142     
       
   143     return CMceComCodec::SetAllowedBitrates( aBitrates );
       
   144     }
       
   145        
       
   146 // -----------------------------------------------------------------------------
       
   147 // CMceComDtmfCodec::SetCodecMode
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 TInt CMceComDtmfCodec::SetCodecMode( TUint aCodecMode )
       
   151     {
       
   152     if ( EMceOutbound == aCodecMode || EMceInbound == aCodecMode )
       
   153         {
       
   154         iCodecMode = aCodecMode;
       
   155         return KErrNone;
       
   156         }
       
   157     else
       
   158         {
       
   159         return KErrNotSupported;
       
   160         }
       
   161     }
       
   162 
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CMceComDtmfCodec::SetPayloadType
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 TInt CMceComDtmfCodec::SetPayloadType( TUint8 aPayloadType )
       
   169     {
       
   170     if ( KMinDynPayloadType <= aPayloadType )
       
   171         {
       
   172         return CMceComCodec::SetPayloadType( aPayloadType );
       
   173         }
       
   174     else
       
   175         {
       
   176         return KErrNotSupported;
       
   177         }
       
   178     }
       
   179 
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CMceComDtmfCodec::GetMaxBitRate
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 TUint CMceComDtmfCodec::GetMaxBitRate()
       
   186 	{
       
   187     return 0;
       
   188     }   
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CMceComDtmfCodec::SetEnabled
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CMceComDtmfCodec::SetEnabled( TBool /*aIsEnabled*/ )
       
   195     {
       
   196     // Dtmf codec cannot be disabled
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CMceComDtmfCodec::SendSupported
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TBool CMceComDtmfCodec::SendSupported()
       
   204     {
       
   205     return EFalse;
       
   206     }
       
   207 
       
   208 #ifdef MCE_COMMON_SERVER_SIDE
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CMceComDtmfCodec::DoMccValidateL
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 CMceComCodec* CMceComDtmfCodec::DoMccValidateL( CMccCodecInformation& aMccCodec,
       
   215                                                 CMceSrvStream& /*aStream*/,
       
   216                                                 TMceNegotiationRole /*aRole*/ )
       
   217     {
       
   218     //if answerer mcc codec represents the received offer and codec the answer
       
   219     //if offerer codec represents the sent offer and mcc codec the answer
       
   220     
       
   221     TBool notValid = ( iAllowedBitrates && aMccCodec.AllowedBitrates() == 0 );
       
   222 	
       
   223 	User::LeaveIfError( notValid ? KErrNotSupported : KErrNone );
       
   224 	
       
   225 	return NULL;
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CMceComDtmfCodec::DoDecodeAudioL
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 
       
   233 void CMceComDtmfCodec::DoDecodeAudioL( 
       
   234     TInt aCodecIndex,
       
   235     RPointerArray<CMceSrvStream>& aStreams,
       
   236     CMceComAudioStream& aAudio,
       
   237     CMceMediaManager& aManager )
       
   238     {
       
   239     // Special handling for dtmf codecs, need to create dummy source
       
   240     // for dtmf uplink and dummy sink for dtmf downlink
       
   241     //
       
   242     if ( IS_RECEIVESTREAM( &aAudio ) )
       
   243         {
       
   244         if ( aAudio.Source()->Type() == KMceRTPSource )
       
   245             {
       
   246             CMceComMediaSink& emptySink = aAudio.EmptySinkL();
       
   247             CMceSrvStream* srvStream = 
       
   248                 CMceSrvStream::NewL( aManager, 
       
   249                                      aAudio, 
       
   250                                      *aAudio.Source(),
       
   251                                      emptySink,
       
   252                                      *this );
       
   253             CleanupStack::PushL( srvStream );
       
   254             MCEMM_DEBUG_STREAM( "CMceComDtmfCodec::DoDecodeAudioL(): decoded dtmf downlink", 
       
   255                                 *srvStream );
       
   256             aStreams.AppendL( srvStream );
       
   257             CleanupStack::Pop( srvStream );
       
   258             }
       
   259         }
       
   260     else
       
   261         {
       
   262         CMceComMediaSink* rtpSink = NULL;
       
   263         for( TInt sinkNdx = 0; sinkNdx < aAudio.Sinks().Count() && !rtpSink; sinkNdx++ )
       
   264             {
       
   265             if ( aAudio.Sinks()[ sinkNdx ]->Type() == KMceRTPSink )
       
   266                 {
       
   267                 rtpSink = aAudio.Sinks()[ sinkNdx ];
       
   268                 }
       
   269             }   
       
   270         if ( rtpSink )
       
   271             {
       
   272             CMceComMediaSource& emptySource = aAudio.EmptySourceL();
       
   273             CMceSrvStream* srvStream = 
       
   274                 CMceSrvStream::NewL( aManager, 
       
   275                                      aAudio, 
       
   276                                      emptySource,
       
   277                                      *rtpSink,
       
   278                                      *this );
       
   279             CleanupStack::PushL( srvStream );
       
   280             MCEMM_DEBUG_STREAM( "CMceComDtmfCodec::DoDecodeAudioL(): decoded dtmf uplink", 
       
   281                                 *srvStream );
       
   282             aStreams.AppendL( srvStream );
       
   283             CleanupStack::Pop( srvStream );
       
   284             }
       
   285         }
       
   286     
       
   287     // As dtmf cannot be used for streaming, select some other codec
       
   288     // for sending.    
       
   289 
       
   290     const TInt codecCount = aAudio.CodecCount();
       
   291 
       
   292     for ( TInt i = 0 ; i < codecCount ; ++i )
       
   293         {
       
   294         UpdateSendCodec( aCodecIndex, aAudio, *aAudio.CodecL( i ) );
       
   295         }
       
   296     }
       
   297     
       
   298 #endif
       
   299     
       
   300 // End of File
       
   301     
       
   302