multimediacommscontroller/mmccsubcontroller/src/mcccodecconfigurator.cpp
changeset 0 1bce908db942
child 26 bcc434605a01
child 33 f40c1a748eb9
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004-2008 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:    Codec configurator for Mcc subthreads
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <mmf/server/mmfaudioinput.h>
       
    23 #include <mmf/server/mmfaudiooutput.h>
       
    24 #include <mmf/server/mmfformat.h>
       
    25 #include <e32math.h>
       
    26 
       
    27 #include <3gplibrary/mp4lib.h>
       
    28 
       
    29 #include <SpeechEncoderConfig.h>
       
    30 #include <ErrorConcealmentIntfc.h>
       
    31 #include <G729DecoderIntfc.h>
       
    32 #include <G729EncoderIntfc.h>
       
    33 #include <G711DecoderIntfc.h>
       
    34 #include <G711EncoderIntfc.h>
       
    35 #include <IlbcDecoderIntfc.h>
       
    36 #include <IlbcEncoderIntfc.h>
       
    37 
       
    38 #include "mcccodecconfigurator.h"
       
    39 #include "mccinternalcodecs.h"
       
    40 #include "mmcccodecinformation.h"
       
    41 #include "mmccinterfacedef.h"
       
    42 #include "mccinternaldef.h"
       
    43 #include "formatstatemachine.h"
       
    44 
       
    45 #include "mccvideosource.h"
       
    46 #include "mccvideosink.h"
       
    47 #include "mccfilesink.h"
       
    48 
       
    49 #include "mccsubcontrollerlogs.h"
       
    50 #include "dtmfpayloadformatwrite.h"
       
    51 #include "dtmfpayloadformatread.h"
       
    52 
       
    53 // LOCAL CONSTANTS
       
    54 // AMR-NB Codec possible bitrates
       
    55 const TInt KAmrNbBitrate475 = 4750;
       
    56 const TInt KAmrNbBitrate515 = 5150;
       
    57 const TInt KAmrNbBitrate590 = 5900;
       
    58 const TInt KAmrNbBitrate670 = 6700;
       
    59 const TInt KAmrNbBitrate740 = 7400;
       
    60 const TInt KAmrNbBitrate795 = 7950;
       
    61 const TInt KAmrNbBitrate102 = 10200;
       
    62 const TInt KAmrNbBitrate122 = 12200;
       
    63 
       
    64 // AMR-WB Codec possible bitrates
       
    65 const TInt KAmrWbBitrate660 = 6600;
       
    66 const TInt KAmrWbBitrate885 = 8850;
       
    67 const TInt KAmrWbBitrate1265 = 12650;
       
    68 const TInt KAmrWbBitrate1425 = 14250;
       
    69 const TInt KAmrWbBitrate1585 = 15850;
       
    70 const TInt KAmrWbBitrate1825 = 18250;
       
    71 const TInt KAmrWbBitrate1985 = 19850;
       
    72 const TInt KAmrWbBitrate2305 = 23050;
       
    73 const TInt KAmrWbBitrate2385 = 23850;
       
    74 
       
    75 // iLBC Codec possible bitrates
       
    76 const TInt KIlbcBitrate1520 = 15200;
       
    77 const TInt KIlbcBitrate1333 = 13330;
       
    78 
       
    79 // G.711 Modes
       
    80 const TInt KG711ModeaLaw = 3;
       
    81 const TInt KG711ModeuLaw = 2;
       
    82 
       
    83 // MACROS
       
    84 #define MCC_CODEC_CONF_SET_VAD_L( curr_vad, get_func, new_vad, set_func ) \
       
    85 __SUBCONTROLLER( "MccCodecConfigurator:: setting vad" ) \
       
    86 TBool curr_vad( EFalse ); \
       
    87 TInt get_vad_err = get_func; \
       
    88 __SUBCONTROLLER_INT1( "MccCodecConfigurator:: get vad err:", get_vad_err ) \
       
    89 __SUBCONTROLLER_INT1( "MccCodecConfigurator:: curr vad:", curr_vad ) \
       
    90 if ( !get_vad_err && curr_vad != new_vad ) \
       
    91     { \
       
    92     TRAP_IGNORE(User::LeaveIfError( set_func )); \
       
    93     __SUBCONTROLLER_INT1( "MccCodecConfigurator:: vad set to:", new_vad ) \
       
    94     }
       
    95 
       
    96 #if ( defined __WINSCW__ ) || ( defined __WINS__ ) || ( defined TEST_EUNIT )
       
    97 #define MCC_CODEC_CONF_DISABLE_CONFIGURATION
       
    98 #endif   
       
    99 
       
   100 // ============================ MEMBER FUNCTIONS ===============================
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // MccCodecConfigurator::ConfigureCodecL
       
   104 // Generic codec configuration for codecs
       
   105 // -----------------------------------------------------------------------------
       
   106 void MccCodecConfigurator::ConfigureCodecL( 
       
   107     MDataSource& aDatasource, 
       
   108     MDataSink& aDatasink, 
       
   109     const TMccCodecInfo& aCodec,
       
   110     CMccRtpMediaClock& aClock,
       
   111     CMccSymStreamBase::TCodecState aCodecState,
       
   112     MDataSink* aAssociatedDatasink )
       
   113     {
       
   114 	__SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL" )
       
   115 
       
   116 	__SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, checking codec" )
       
   117     User::LeaveIfError( TMccCodecInfo::CheckCodecInfo( aCodec ) );
       
   118     
       
   119     if( KUidMmfAudioInput == aDatasource.DataSourceType() )
       
   120         {        
       
   121 		__SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, KUidMmfAudioInput" )
       
   122         MMMFAudioInput& record_device = static_cast<MMMFAudioInput&>( aDatasource );
       
   123         CPayloadFormatWrite& format_enc = static_cast<CPayloadFormatWrite&>( aDatasink );
       
   124         DoConfigureLiveAudioUplinkStreamL( record_device, format_enc, aCodec, aClock, aCodecState );
       
   125         }
       
   126     else if( KUidMmfAudioOutput == aDatasink.DataSinkType() )
       
   127         {
       
   128 		__SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, KUidMmfAudioOutput" )
       
   129         MMMFAudioOutput& play_device = static_cast<MMMFAudioOutput&>( aDatasink );
       
   130         CPayloadFormatRead& format_dec = static_cast<CPayloadFormatRead&>( aDatasource );
       
   131         DoConfigureLiveAudioDownlinkStreamL( play_device, format_dec, aCodec, aCodecState );
       
   132         }
       
   133     else if( KMccFileSourceUid == aDatasource.DataSourceType() )
       
   134         {
       
   135         __SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, KMccFileSourceUID" )
       
   136         if ( KMccFileSinkUid != aDatasink.DataSinkType() )
       
   137             {
       
   138     	    CPayloadFormatWrite& format = static_cast<CPayloadFormatWrite&>( aDatasink );
       
   139     	    DoConfigureClipUplinkStreamL( format, aCodec, aAssociatedDatasink, aClock );
       
   140 	        PassPrerollFromSinkToSourceL(aAssociatedDatasink, &aDatasource);
       
   141             }
       
   142         }
       
   143     else if ( KMccFileSinkUid == aDatasink.DataSinkType() )
       
   144 	    {
       
   145         if ( KMccVideoSourceUid == aDatasource.DataSourceType() )
       
   146             {
       
   147             __SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, KMccFileSinkUID, KMccVideoSourceUid" )
       
   148             DoConfigureCameraL( static_cast<CMccVideoSource&>( aDatasource ), aCodec );
       
   149             DoConfigureFileSinkL( static_cast<CMccFileSink&>( aDatasink ), aCodec );
       
   150             }
       
   151         else
       
   152             {
       
   153             __SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, KMccFileSinkUID, source decoder" )
       
   154             CPayloadFormatRead& formatDec = static_cast<CPayloadFormatRead&>( aDatasource );
       
   155 		    TMccCodecInfoBuffer buffer( aCodec );
       
   156             formatDec.ConfigurePayloadFormatL( buffer );
       
   157             }
       
   158 	    }
       
   159     else if( KMccVideoSourceUid == aDatasource.DataSourceType() )
       
   160         {
       
   161 	    CPayloadFormatWrite& format = static_cast<CPayloadFormatWrite&>( aDatasink );
       
   162 		__SUBCONTROLLER( "CMccCodecConfigurator::ConfigureCodecL, KMccVideoSourceUID, video" )
       
   163 	    CMccVideoSource& recordDevice = static_cast<CMccVideoSource&>( aDatasource );
       
   164 	    DoConfigureLiveVideoUplinkStreamL( recordDevice, format, aCodec, aAssociatedDatasink, aClock  );
       
   165         }
       
   166     else if( KMccVideoSinkUid == aDatasink.DataSinkType() )
       
   167         {
       
   168 		__SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, KMccVideoSinkUID" )
       
   169 		if ( KUidMmfFormatDecode == aDatasource.DataSourceType() )
       
   170 		    {
       
   171 		    __SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, source decoder" )
       
   172 	        CPayloadFormatRead& formatDec = static_cast<CPayloadFormatRead&>( aDatasource );
       
   173             DoConfigureLiveVideoDownlinkStreamL( &aDatasink, formatDec, aCodec );
       
   174 		    }
       
   175         }        
       
   176     else if ( aCodec.iFourCC == KMccFourCCIdDTMF )
       
   177         {
       
   178         __SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, KMccFourCCIdDTMF" )
       
   179         
       
   180         if ( KUidMmfFormatDecode == aDatasource.DataSourceType() )
       
   181             {
       
   182             CPayloadFormatRead& formatDec = static_cast<CPayloadFormatRead&>( aDatasource );
       
   183             DoConfigureDtmfFormatL( formatDec, aCodec );
       
   184             }
       
   185         else if ( KUidMmfFormatEncode == aDatasink.DataSinkType() )
       
   186             {
       
   187             CPayloadFormatWrite& formatEnc = static_cast<CPayloadFormatWrite&>( aDatasink );
       
   188             DoConfigureDtmfFormatL( formatEnc, aCodec, aClock );
       
   189             }
       
   190         else
       
   191             {
       
   192             User::Leave( KErrArgument );
       
   193             }
       
   194         }
       
   195     else
       
   196         {
       
   197 		__SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, KErrArgument" )
       
   198         User::Leave( KErrArgument );
       
   199         }
       
   200 	__SUBCONTROLLER( "MccCodecConfigurator::ConfigureCodecL, exit" )
       
   201     }
       
   202 
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // MccCodecConfigurator::DoConfigureAmrL
       
   206 // Configures the AMR record device
       
   207 // -----------------------------------------------------------------------------
       
   208 void MccCodecConfigurator::DoConfigureAmrL( 
       
   209     MMMFAudioOutput& aPlaybackDev, 
       
   210     const TMccCodecInfo& aCodec )
       
   211     {
       
   212 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureAmrL, decoder" )
       
   213 
       
   214     TFourCC fourcc( aCodec.iFourCC );
       
   215     const TUint32 fourccVal = fourcc.FourCC();
       
   216     if ( ( fourccVal == KMccFourCCIdAMRNB && 
       
   217            !IsSupportedAmrNbBitrate( aCodec.iBitrate ) ) ||
       
   218          ( fourccVal == KMccFourCCIdAMRWB && 
       
   219            !IsSupportedAmrWbBitrate( aCodec.iBitrate ) ) )
       
   220         {
       
   221         User::Leave( KErrNotSupported );
       
   222         }
       
   223         
       
   224     __SUBCONTROLLER( "MccCodecConfigurator, bitrate allowed" )
       
   225     
       
   226     CErrorConcealmentIntfc* errorConcealIf = 
       
   227         CErrorConcealmentIntfc::NewL( aPlaybackDev.SoundDevice() );
       
   228       
       
   229     errorConcealIf->SetFrameMode( ETrue );
       
   230     
       
   231     delete errorConcealIf;
       
   232     errorConcealIf = NULL;
       
   233 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureAmrL, exit" )
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // MccCodecConfigurator::DoConfigureAmrL
       
   238 // Configures the AMR playback device
       
   239 // -----------------------------------------------------------------------------
       
   240 void MccCodecConfigurator::DoConfigureAmrL( 
       
   241     MMMFAudioInput& aRecordDev, 
       
   242     const TMccCodecInfo& aCodec )
       
   243     {
       
   244     
       
   245 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureAmrL, encoder" )
       
   246     
       
   247     TFourCC fourcc( aCodec.iFourCC );
       
   248     const TUint32 fourccVal = fourcc.FourCC();
       
   249     if ( ( fourccVal == KMccFourCCIdAMRNB && 
       
   250            !IsSupportedAmrNbBitrate( aCodec.iBitrate ) ) ||
       
   251          ( fourccVal == KMccFourCCIdAMRWB && 
       
   252            !IsSupportedAmrWbBitrate( aCodec.iBitrate ) ) )
       
   253         {
       
   254         User::Leave( KErrNotSupported );
       
   255         }
       
   256         
       
   257     __SUBCONTROLLER( "MccCodecConfigurator, bitrate allowed" )
       
   258     
       
   259     CSpeechEncoderConfig* speechEncConfIf = 
       
   260             CSpeechEncoderConfig::NewL( aRecordDev.SoundDevice() );
       
   261     CleanupStack::PushL( speechEncConfIf );
       
   262     
       
   263 	__SUBCONTROLLER( "MccCodecConfigurator, setting VAD" )
       
   264 	
       
   265     TBool requestedEnableVad = aCodec.iEnableDTX;
       
   266 	
       
   267 	MCC_CODEC_CONF_SET_VAD_L( currentVad,
       
   268 	                          speechEncConfIf->GetVadMode( currentVad ),
       
   269 	                          requestedEnableVad, 
       
   270                         	  speechEncConfIf->SetVadMode( requestedEnableVad ) )
       
   271 
       
   272     __SUBCONTROLLER_INT1( "MccCodecConfigurator, setting bitrate", aCodec.iBitrate )
       
   273     TUint bitrate( 0 );
       
   274     User::LeaveIfError( speechEncConfIf->GetBitrate( bitrate ) );
       
   275     if ( bitrate != aCodec.iBitrate )
       
   276         {
       
   277         User::LeaveIfError( speechEncConfIf->SetBitrate( aCodec.iBitrate ) );
       
   278         }
       
   279 
       
   280     CleanupStack::PopAndDestroy( speechEncConfIf );
       
   281 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureAmrL, exit" )
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // MccCodecConfigurator::DoConfigureG711L
       
   286 // Configures the G.711 playback device
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void MccCodecConfigurator::DoConfigureG711L( 
       
   290     MMMFAudioOutput& aPlaybackDev, 
       
   291     const TMccCodecInfo& aCodec,
       
   292     CMccSymStreamBase::TCodecState aCodecState )
       
   293     {
       
   294 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureG711L, decoder" )
       
   295 
       
   296     CG711DecoderIntfc* g711DecIf = 
       
   297             CG711DecoderIntfc::NewL( aPlaybackDev.SoundDevice() );
       
   298     CleanupStack::PushL( g711DecIf );
       
   299     
       
   300     // Cannot change mode on fly, 
       
   301     // changing it only right after the codec has been loaded
       
   302     if ( aCodecState == CMccSymStreamBase::EStateCodecLoaded )
       
   303         {
       
   304         if( KG711ModeaLaw == aCodec.iCodecMode )
       
   305             {
       
   306             __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureG711L, aLaw" )
       
   307             User::LeaveIfError( g711DecIf->SetDecoderMode(
       
   308                 CG711DecoderIntfc::EDecALaw ) );
       
   309             }
       
   310         else if( KG711ModeuLaw == aCodec.iCodecMode )
       
   311             {
       
   312             __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureG711L, uLaw" )
       
   313             User::LeaveIfError( g711DecIf->SetDecoderMode(
       
   314                 CG711DecoderIntfc::EDecULaw ) );  
       
   315             }
       
   316         else
       
   317             {
       
   318             User::Leave( KErrNotSupported );
       
   319             }
       
   320         }
       
   321           
       
   322     TBool enableCng = ConvertBoolean( aCodec.iEnableDTX );
       
   323     
       
   324     MCC_CODEC_CONF_SET_VAD_L( currentVad,
       
   325 	                          g711DecIf->GetCng( currentVad ),
       
   326 	                          enableCng, 
       
   327                         	  g711DecIf->SetCng( enableCng ) )
       
   328         
       
   329     CleanupStack::PopAndDestroy( g711DecIf );
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // MccCodecConfigurator::DoConfigureG711L
       
   334 // Configures the G.711 record device
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 void MccCodecConfigurator::DoConfigureG711L( 
       
   338     MMMFAudioInput& aRecordDev, 
       
   339     const TMccCodecInfo& aCodec,
       
   340     CMccSymStreamBase::TCodecState aCodecState )
       
   341     {
       
   342 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureG711L, encoder" )
       
   343 
       
   344     CG711EncoderIntfc* g711EncIf = 
       
   345             CG711EncoderIntfc::NewL( aRecordDev.SoundDevice() );
       
   346     CleanupStack::PushL( g711EncIf );
       
   347 
       
   348     // Cannot change mode on fly, 
       
   349     // changing it only right after the codec has been loaded
       
   350     if ( aCodecState == CMccSymStreamBase::EStateCodecLoaded )
       
   351         {
       
   352         if( KG711ModeaLaw == aCodec.iCodecMode )
       
   353             {
       
   354             __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureG711L, aLaw" )
       
   355             User::LeaveIfError( g711EncIf->SetEncoderMode(
       
   356                 CG711EncoderIntfc::EEncALaw ) );
       
   357             }
       
   358         else if ( KG711ModeuLaw == aCodec.iCodecMode )
       
   359             {
       
   360             __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureG711L, uLaw" )
       
   361             User::LeaveIfError( g711EncIf->SetEncoderMode(
       
   362                 CG711EncoderIntfc::EEncULaw ) );
       
   363             }
       
   364         else
       
   365             {
       
   366             User::Leave( KErrNotSupported );
       
   367             }
       
   368         }
       
   369     
       
   370     TBool enableVad = ConvertBoolean( aCodec.iEnableDTX );
       
   371     
       
   372 	MCC_CODEC_CONF_SET_VAD_L( currentVad,
       
   373 	                          g711EncIf->GetVadMode( currentVad ),
       
   374 	                          enableVad, 
       
   375                         	  g711EncIf->SetVadMode( enableVad ) )                      	  
       
   376  
       
   377     CleanupStack::PopAndDestroy( g711EncIf );
       
   378     }
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 // MccCodecConfigurator::DoConfigureG729L
       
   382 // Configures the G.729 playback device
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void MccCodecConfigurator::DoConfigureG729( MMMFAudioOutput& /*aPlaybackDev*/ )
       
   386     {
       
   387 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureG729, decoder, NOP" )
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // MccCodecConfigurator::DoConfigureG729L
       
   392 // Configures the G.729 record device
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void MccCodecConfigurator::DoConfigureG729L( MMMFAudioInput& aRecordDev,
       
   396     TBool aEnableCng )
       
   397     {
       
   398     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureG729, encoder" )
       
   399     
       
   400     CG729EncoderIntfc* encG729If = 
       
   401             CG729EncoderIntfc::NewL( aRecordDev.SoundDevice() );
       
   402     CleanupStack::PushL( encG729If );
       
   403 
       
   404     TBool enableVad = ConvertBoolean( aEnableCng );
       
   405    
       
   406    	MCC_CODEC_CONF_SET_VAD_L( currentVad,
       
   407 	                          encG729If->GetVadMode( currentVad ),
       
   408 	                          enableVad, 
       
   409                         	  encG729If->SetVadMode( enableVad ) )     
       
   410         
       
   411     CleanupStack::PopAndDestroy( encG729If );       
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // MccCodecConfigurator::DoConfigureIlbcL
       
   416 // Configures the iLBC playback device
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 void MccCodecConfigurator::DoConfigureIlbcL( 
       
   420     MMMFAudioOutput& aPlaybackDev, 
       
   421     const TMccCodecInfo& aCodec,
       
   422     CMccSymStreamBase::TCodecState aCodecState )
       
   423     {
       
   424     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureIlbcL decoder" )
       
   425     __SUBCONTROLLER_INT1( "MccCodecConfigurator::DoConfigureIlbcL aCodecState: ",
       
   426         aCodecState )
       
   427     
       
   428     // Cannot change mode nor CNG state on fly, changing it only right after
       
   429     // the codec has been loaded. Same thing applies also to other parameters.
       
   430     if ( CMccSymStreamBase::EStateCodecLoaded == aCodecState )
       
   431         {
       
   432         CIlbcDecoderIntfc* decIlbcIf = 
       
   433             CIlbcDecoderIntfc::NewL( aPlaybackDev.SoundDevice() );
       
   434         CleanupStack::PushL( decIlbcIf );
       
   435     
       
   436         if( KIlbcBitrate1520 == aCodec.iBitrate )
       
   437             {
       
   438             __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureIlbcL, 20ms" )
       
   439             
       
   440             User::LeaveIfError( decIlbcIf->SetDecoderMode(
       
   441                 CIlbcDecoderIntfc::E20msFrame ) );
       
   442             }
       
   443         else if( KIlbcBitrate1333 == aCodec.iBitrate )
       
   444             {
       
   445             __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureIlbcL, 30ms" )
       
   446             
       
   447             User::LeaveIfError( decIlbcIf->SetDecoderMode(
       
   448                 CIlbcDecoderIntfc::E30msFrame ) );
       
   449             }
       
   450         else
       
   451             {
       
   452             User::Leave( KErrNotSupported );
       
   453             }
       
   454             
       
   455             
       
   456         TBool cngEnabled = ConvertBoolean( aCodec.iEnableDTX );
       
   457     
       
   458         MCC_CODEC_CONF_SET_VAD_L( currentVad,
       
   459 	                              decIlbcIf->GetCng( currentVad ),
       
   460 	                              cngEnabled, 
       
   461                         	      decIlbcIf->SetCng( cngEnabled ) ) 
       
   462         
       
   463         CleanupStack::PopAndDestroy( decIlbcIf );
       
   464         }
       
   465         
       
   466     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureIlbcL decoder, Exit" )
       
   467     }
       
   468 
       
   469 // -----------------------------------------------------------------------------
       
   470 // MccCodecConfigurator::DoConfigureIlbcL
       
   471 // Configures the iLBC record device
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 void MccCodecConfigurator::DoConfigureIlbcL( 
       
   475     MMMFAudioInput& aRecordDev, 
       
   476     const TMccCodecInfo& aCodec,
       
   477     CMccSymStreamBase::TCodecState aCodecState )
       
   478     {
       
   479     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureIlbcL encoder" )
       
   480     __SUBCONTROLLER_INT1( "MccCodecConfigurator::DoConfigureIlbcL aCodecState: ",
       
   481         aCodecState )
       
   482     
       
   483     // Cannot change mode nor VAD state on fly, changing it only right after
       
   484     // the codec has been loaded. Same thing applies also to other parameters.
       
   485     if ( CMccSymStreamBase::EStateCodecLoaded == aCodecState )
       
   486         {
       
   487         CIlbcEncoderIntfc* encIlbcIf = 
       
   488             CIlbcEncoderIntfc::NewL( aRecordDev.SoundDevice() );
       
   489         CleanupStack::PushL( encIlbcIf );
       
   490     
       
   491         if( KIlbcBitrate1520 == aCodec.iBitrate )
       
   492             {
       
   493             __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureIlbcL, 20ms" )
       
   494             
       
   495             User::LeaveIfError( encIlbcIf->SetEncoderMode(
       
   496                 CIlbcEncoderIntfc::E20msFrame ) );
       
   497             }
       
   498         else if ( KIlbcBitrate1333 == aCodec.iBitrate )
       
   499             {
       
   500             __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureIlbcL, 30ms" )
       
   501             
       
   502             User::LeaveIfError( encIlbcIf->SetEncoderMode(
       
   503                 CIlbcEncoderIntfc::E30msFrame ) );
       
   504             }
       
   505         else
       
   506             {
       
   507             User::Leave( KErrNotSupported );
       
   508             }
       
   509         
       
   510         TBool vadEnabled = ConvertBoolean(  aCodec.iEnableDTX );
       
   511         
       
   512         MCC_CODEC_CONF_SET_VAD_L( currentVad,
       
   513 	                              encIlbcIf->GetVadMode( currentVad ),
       
   514 	                              vadEnabled, 
       
   515                         	      encIlbcIf->SetVadMode( vadEnabled ) )
       
   516         
       
   517         CleanupStack::PopAndDestroy( encIlbcIf );
       
   518         }
       
   519         
       
   520     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureIlbcL encoder, Exit" )
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // MccCodecConfigurator::DoConfigureCameraL
       
   525 // -----------------------------------------------------------------------------
       
   526 void MccCodecConfigurator::DoConfigureCameraL( CMccVideoSource& aVideoSource, 
       
   527     const TMccCodecInfo& aCodec )
       
   528 	{
       
   529 	if( aCodec.iType == KUidMediaTypeVideo )
       
   530 		{
       
   531 		aVideoSource.SetVideoCodecL( aCodec );
       
   532 		}
       
   533 	else
       
   534 		{
       
   535 		aVideoSource.SetAudioCodecL( aCodec );
       
   536 		}	
       
   537 	}
       
   538 
       
   539 // -----------------------------------------------------------------------------
       
   540 // MccCodecConfigurator::DoConfigureCameraL
       
   541 // -----------------------------------------------------------------------------
       
   542 void MccCodecConfigurator::DoConfigureFileSinkL( CMccFileSink& aFileSink, 
       
   543     const TMccCodecInfo& aCodec )
       
   544     {
       
   545     if( aCodec.iType == KUidMediaTypeVideo )
       
   546 		{
       
   547 		aFileSink.SetVideoCodecL( aCodec );
       
   548 		}
       
   549 	else
       
   550 		{
       
   551 		aFileSink.SetAudioCodecL( aCodec );
       
   552 		}	
       
   553     }
       
   554     
       
   555 // -----------------------------------------------------------------------------
       
   556 // MccCodecConfigurator::DoGetCameraConfigurationL
       
   557 // -----------------------------------------------------------------------------
       
   558 void MccCodecConfigurator::DoGetCameraConfigurationL( 
       
   559     const TMccCodecInfo& /*aCodec*/, 
       
   560     const TDesC8& /*aParam*/ )
       
   561 	{
       
   562 	}
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // MccCodecConfigurator::DoGetClipConfigurationL
       
   566 // -----------------------------------------------------------------------------
       
   567 void MccCodecConfigurator::DoGetClipConfigurationL( TDes8& aParam )
       
   568 	{
       
   569 	__SUBCONTROLLER( "MccCodecConfigurator::DoGetClipConfigurationL" )
       
   570 	
       
   571 	TMccFileSourceSetting& setting = 
       
   572 	    (*reinterpret_cast<TMccFileSourceSettingBuf*>( &aParam ))();
       
   573 	
       
   574 	MP4Handle mp4Handle;
       
   575 	MP4Err err = MP4_OK;
       
   576     
       
   577     TFileName fileName( setting.iFileName );
       
   578     
       
   579     const TInt KMccZeroTerminatorLen = 1;
       
   580     __ASSERT_ALWAYS( 
       
   581 	    fileName.Length() + KMccZeroTerminatorLen <= fileName.MaxLength(),
       
   582 	    User::Leave( KErrOverflow ) );
       
   583     
       
   584     err = MP4ParseOpen( &mp4Handle, (wchar_t *) fileName.PtrZ() );
       
   585     
       
   586     if ( err == MP4_OUT_OF_MEMORY )
       
   587         {
       
   588         User::Leave( KErrNoMemory );
       
   589         }
       
   590     
       
   591     __ASSERT_ALWAYS( err == MP4_OK, User::Leave( KErrNotFound ) );
       
   592     
       
   593     // Read audio settings
       
   594     //
       
   595 	mp4_u32 audioLength = 0;
       
   596     mp4_u32 audioType;
       
   597 	mp4_u8 framesPerSample;
       
   598 	mp4_u32 audioTimeScale;
       
   599 	mp4_u32 audioAverageBitRate = 0;
       
   600 	
       
   601 	err = MP4_OK;	
       
   602 	err = MP4ParseRequestAudioDescription( mp4Handle,
       
   603 	        ( mp4_u32* ) &audioLength, ( mp4_u32* ) &audioType,
       
   604 	        ( mp4_u8* ) &framesPerSample, ( mp4_u32* ) &audioTimeScale,
       
   605 	        ( mp4_u32* ) &audioAverageBitRate );
       
   606 	    	
       
   607 	if ( err == MP4_OK && audioType != MP4_TYPE_NONE )
       
   608 	    {
       
   609 	    if ( audioType == MP4_TYPE_AMR_NB )
       
   610 	        {
       
   611 	        __SUBCONTROLLER( 
       
   612 	        "MccCodecConfigurator::DoGetClipConfigurationL, file contains AMR" )
       
   613 	        setting.iAudioFourCC = TFourCC( KMccFourCCIdAMRNB );
       
   614 	        setting.iAudioBitRate = audioAverageBitRate;
       
   615 	        }
       
   616 	    else
       
   617 	        {
       
   618 	        __SUBCONTROLLER( 
       
   619 	        "MccCodecConfigurator::DoGetClipConfigurationL, file contains unsupported audio" )
       
   620 	        setting.iAudioFourCC = TFourCC( KMccFourCCUnsupported );
       
   621 	        }
       
   622 	    }
       
   623 	else 
       
   624 	    {
       
   625 	    __SUBCONTROLLER( "MccCodecConfigurator::DoGetClipConfigurationL, no audio" )
       
   626         setting.iAudioFourCC = TFourCC();
       
   627 	    }
       
   628 	
       
   629 	
       
   630 	// Read video settings 
       
   631 	//  
       
   632 	mp4_u32 videoLength = 0;
       
   633 	TReal frameRate;
       
   634 	mp4_u32 videoType;
       
   635 	mp4_u32 videoWidth;
       
   636 	mp4_u32 videoHeight;
       
   637 	mp4_u32 videoTimeScale;
       
   638 	mp4_u32 videoAverageBitRate;
       
   639 	mp4_u32 streamSize;
       
   640 	
       
   641 	err = MP4_OK;
       
   642     err = MP4ParseRequestVideoDescription( mp4Handle,
       
   643 		( mp4_u32* ) &videoLength,  &frameRate, ( mp4_u32* ) &videoType,
       
   644 		( mp4_u32* ) &videoWidth,  ( mp4_u32* ) &videoHeight,
       
   645         ( mp4_u32* ) &videoTimeScale );
       
   646 
       
   647     if ( err == MP4_OK && videoType != MP4_TYPE_NONE )
       
   648         {
       
   649         if ( videoType == MP4_TYPE_H263_PROFILE_0 || 
       
   650              videoType == MP4_TYPE_AVC_PROFILE_BASELINE )
       
   651             {
       
   652             __SUBCONTROLLER( 
       
   653             "MccCodecConfigurator::DoGetClipConfigurationL, file contains supported video" )
       
   654             
       
   655             err = MP4ParseRequestStreamDescription( mp4Handle,
       
   656                 ( mp4_u32* ) &streamSize, ( mp4_u32* ) &videoAverageBitRate );
       
   657             
       
   658             __ASSERT_ALWAYS( err == MP4_OK, User::Leave( KErrGeneral ) );
       
   659             
       
   660             if ( videoType == MP4_TYPE_H263_PROFILE_0 )
       
   661                 {
       
   662                 __SUBCONTROLLER( "H263" )
       
   663                 setting.iVideoFourCC = TFourCC( KMccFourCCIdH263 );
       
   664                 }
       
   665             else
       
   666                 {
       
   667                 __SUBCONTROLLER( "AVC" )
       
   668                 setting.iVideoFourCC = TFourCC( KMccFourCCIdAVC );
       
   669                 }
       
   670             // Round to have zero decimals for clearness sake
       
   671             User::LeaveIfError( Math::Round( setting.iVideoFrameRate, frameRate, 0 ) );
       
   672             setting.iVideoFrameSize.iWidth = videoWidth;
       
   673             setting.iVideoFrameSize.iHeight = videoHeight;
       
   674             
       
   675             // Average bitrate is for the whole stream, 
       
   676             // subtract audio average to get video average
       
   677             setting.iVideoBitRate = videoAverageBitRate - audioAverageBitRate;
       
   678             }
       
   679         else
       
   680             {
       
   681             __SUBCONTROLLER( 
       
   682             "MccCodecConfigurator::DoGetClipConfigurationL, file contains unsupported video" )
       
   683             setting.iVideoFourCC = TFourCC( KMccFourCCUnsupported );
       
   684             }
       
   685         }
       
   686     
       
   687     else 
       
   688     	{
       
   689     	__SUBCONTROLLER( 
       
   690     	"MccCodecConfigurator::DoGetClipConfigurationL, no video" )
       
   691         setting.iVideoFourCC = TFourCC();
       
   692     	}
       
   693     		
       
   694     MP4ParseClose( mp4Handle );
       
   695     
       
   696     // Audio and video might have different duration, take longer one
       
   697     //
       
   698     const TUint KMccMilliSecsToMicroSecs = 1000;
       
   699     TUint32 duration = videoLength > audioLength ? videoLength : audioLength;
       
   700     duration = duration * KMccMilliSecsToMicroSecs;
       
   701     setting.iDuration = duration;
       
   702     
       
   703     setting.iPosition = 0;
       
   704     
       
   705     __SUBCONTROLLER_INT1( "duration:", setting.iDuration.Int64() )  
       
   706     __SUBCONTROLLER_INT1( "position:", setting.iPosition.Int64() )  
       
   707     __SUBCONTROLLER_INT1( "videoframerate:", (TInt) setting.iVideoFrameRate )  
       
   708     __SUBCONTROLLER_INT1( "videobitrate:", setting.iVideoBitRate )  
       
   709     __SUBCONTROLLER_INT2( "videoframesize width:", 
       
   710                           setting.iVideoFrameSize.iWidth, 
       
   711                           " height:",
       
   712                           setting.iVideoFrameSize.iHeight )  
       
   713     __SUBCONTROLLER_INT1( "audiobitrate:", setting.iAudioBitRate ) 
       
   714     __SUBCONTROLLER_INT1( "audio fourcc:", setting.iAudioFourCC.FourCC() ) 
       
   715     __SUBCONTROLLER_INT1( "video fourcc:", setting.iVideoFourCC.FourCC() ) 
       
   716     
       
   717     __SUBCONTROLLER( "MccCodecConfigurator::DoGetClipConfigurationL, exit" )
       
   718 	}
       
   719 	
       
   720 // -----------------------------------------------------------------------------
       
   721 // MccCodecConfigurator::DoConfigureLiveAudioUplinkStreamL
       
   722 // Uplink/Record codec configuration
       
   723 // -----------------------------------------------------------------------------
       
   724 void MccCodecConfigurator::DoConfigureLiveAudioUplinkStreamL( 
       
   725     MMMFAudioInput& aRecordDevice, 
       
   726     CPayloadFormatWrite& aFormatter, 
       
   727     const TMccCodecInfo& aCodec,
       
   728     CMccRtpMediaClock& aClock,
       
   729     CMccSymStreamBase::TCodecState aCodecState )
       
   730     {
       
   731 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureLiveAudioUplinkStreamL" )
       
   732     
       
   733     if ( aCodecState >= CMccSymStreamBase::EStateCodecLoaded )
       
   734         {
       
   735         TFourCC fourcc( aCodec.iFourCC );
       
   736         
       
   737         switch( fourcc.FourCC() )
       
   738             {
       
   739             case KMccFourCCIdAMRNB:
       
   740             case KMccFourCCIdAMRWB:
       
   741                 {
       
   742                 #ifdef MCC_CODEC_CONF_DISABLE_CONFIGURATION
       
   743 
       
   744                 // Suppress compiler warnings
       
   745                 aRecordDevice = aRecordDevice;
       
   746                 
       
   747                 #else
       
   748                 
       
   749                 DoConfigureAmrL( aRecordDevice, aCodec );
       
   750                 
       
   751                 #endif
       
   752                 }
       
   753                 break;
       
   754 
       
   755             case KMccFourCCIdG711:
       
   756                 {
       
   757                 #ifndef MCC_CODEC_CONF_DISABLE_CONFIGURATION
       
   758                 
       
   759                 DoConfigureG711L( aRecordDevice, aCodec, aCodecState );
       
   760                 
       
   761                 #endif
       
   762                 }
       
   763                 break;
       
   764             case KMccFourCCIdILBC:
       
   765                 {
       
   766                 #ifndef MCC_CODEC_CONF_DISABLE_CONFIGURATION
       
   767                 
       
   768                 DoConfigureIlbcL( aRecordDevice, aCodec, aCodecState );
       
   769                 
       
   770                 #endif
       
   771                 }
       
   772                 break;
       
   773             case KMccFourCCIdG729:
       
   774                 {
       
   775                 #ifndef MCC_CODEC_CONF_DISABLE_CONFIGURATION
       
   776                 
       
   777                 DoConfigureG729L( aRecordDevice, aCodec.iEnableDTX );
       
   778                 
       
   779                 #endif
       
   780                 }
       
   781                 break;
       
   782             default:
       
   783     			__SUBCONTROLLER_INT1( "MccCodecConfigurator, KErrNotSupported", fourcc.FourCC() )
       
   784                 
       
   785                 User::Leave( KErrNotSupported );
       
   786                 break;
       
   787             }
       
   788         }
       
   789 
       
   790     const TMccCodecInfoBuffer buffer( aCodec );
       
   791     aFormatter.ConfigurePayloadFormatL( buffer, aClock );
       
   792 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureLiveAudioUplinkStreamL, exit" )
       
   793     }
       
   794 
       
   795 // -----------------------------------------------------------------------------
       
   796 // MccCodecConfigurator::DoConfigureLiveAudioDownlinkStreamL
       
   797 // Downlink/Playback codec configuration
       
   798 // -----------------------------------------------------------------------------
       
   799 void MccCodecConfigurator::DoConfigureLiveAudioDownlinkStreamL( 
       
   800     MMMFAudioOutput& aPlayDevice, 
       
   801     CPayloadFormatRead& aFormatter, 
       
   802     const TMccCodecInfo& aCodec,
       
   803     CMccSymStreamBase::TCodecState aCodecState )
       
   804     {
       
   805     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureLiveAudioDownlinkStreamL" )
       
   806     
       
   807     if ( aCodecState >= CMccSymStreamBase::EStateCodecLoaded )
       
   808         {
       
   809         TFourCC fourcc = aCodec.iFourCC;
       
   810         
       
   811         switch( fourcc.FourCC() )
       
   812             {
       
   813             case KMccFourCCIdAMRNB:
       
   814             case KMccFourCCIdAMRWB:
       
   815                 {
       
   816                 
       
   817                 #ifndef MCC_CODEC_CONF_DISABLE_CONFIGURATION
       
   818                 
       
   819                 DoConfigureAmrL( aPlayDevice, aCodec );
       
   820                 
       
   821                 #endif
       
   822                 }
       
   823                 break;
       
   824 
       
   825             case KMccFourCCIdG711:
       
   826                 {
       
   827                 #ifndef MCC_CODEC_CONF_DISABLE_CONFIGURATION
       
   828                 
       
   829                 DoConfigureG711L( aPlayDevice, aCodec, aCodecState );
       
   830                 
       
   831                 #endif
       
   832                 }
       
   833                 break;
       
   834             case KMccFourCCIdILBC:
       
   835                 {
       
   836                 #ifndef MCC_CODEC_CONF_DISABLE_CONFIGURATION
       
   837 
       
   838                 DoConfigureIlbcL( aPlayDevice, aCodec, aCodecState );
       
   839                 
       
   840                 #endif
       
   841                 }
       
   842                 break;
       
   843             case KMccFourCCIdG729:
       
   844                 {
       
   845                 // Nothing to do for G.729 decoder, but VoIP traces need that function
       
   846                 // to be called. This is call is safe for WINSCW also.
       
   847                 DoConfigureG729( aPlayDevice );
       
   848                 }
       
   849                 break;
       
   850             default:
       
   851                 User::Leave( KErrNotSupported );
       
   852                 break;
       
   853             }
       
   854         }
       
   855     
       
   856     const TMccCodecInfoBuffer buffer( aCodec );
       
   857     aFormatter.ConfigurePayloadFormatL( buffer );
       
   858 	__SUBCONTROLLER( "MccCodecConfigurator::DoConfigureLiveAudioDownlinkStreamL, exit" )
       
   859     }
       
   860     
       
   861 // -----------------------------------------------------------------------------
       
   862 // MccCodecConfigurator::DoConfigureDisplayL
       
   863 // Uplink/Display codec configuration
       
   864 // -----------------------------------------------------------------------------
       
   865 void MccCodecConfigurator::DoConfigureDisplayL(  
       
   866     const TMccCodecInfo& aCodec,
       
   867     MDataSink* aDatasink )
       
   868     {        
       
   869     if ( aDatasink && aDatasink->DataSinkType() == KMccVideoSinkUid )
       
   870         {
       
   871         if ( aCodec.iType == KUidMediaTypeAudio )
       
   872             {
       
   873             static_cast<CMccVideoSink*>( aDatasink )->SetAudioCodecL( aCodec );
       
   874             }
       
   875         else
       
   876             {
       
   877             static_cast<CMccVideoSink*>( aDatasink )->SetVideoCodecL( aCodec );
       
   878             }
       
   879         }
       
   880     }
       
   881 
       
   882 // -----------------------------------------------------------------------------
       
   883 // MccCodecConfigurator::PassPrerollFromSinkToSourceL
       
   884 // Passes preroll value from sink to source
       
   885 // -----------------------------------------------------------------------------
       
   886 void MccCodecConfigurator::PassPrerollFromSinkToSourceL(
       
   887 	MDataSink* aDataSink,  MDataSource* aDataSource)
       
   888     {
       
   889     if ( aDataSource &&
       
   890          aDataSink &&
       
   891          aDataSource->DataSourceType().iUid == KImplUidMccFileSource &&
       
   892          aDataSink->DataSinkType().iUid == KImplUidMccVideoSink )
       
   893         {
       
   894         // Pass preroll value from sink to source
       
   895         CMccDataSink* mccVideoSink = static_cast<CMccDataSink*>( aDataSink );
       
   896         __ASSERT_DEBUG( mccVideoSink, 
       
   897         User::Panic(
       
   898         	_L("MccCodecConfigurator::PassPrerollFromSinkToSourceL mccVideoSink == 0"), 
       
   899         	KErrArgument ) );
       
   900         __ASSERT_ALWAYS( mccVideoSink, User::Leave(KErrArgument) );
       
   901         CMccDataSource* mccFileSource = static_cast<CMccDataSource*>( aDataSource );
       
   902         __ASSERT_DEBUG( mccFileSource, 
       
   903         User::Panic(
       
   904         	_L("MccCodecConfigurator::PassPrerollFromSinkToSourceL mccFileSource == 0"), 
       
   905         	KErrArgument ) );
       
   906         __ASSERT_ALWAYS( mccFileSource, User::Leave(KErrArgument) );
       
   907 
       
   908         TPckgBuf<TInt> packageBuffer;
       
   909         mccVideoSink->GetParameterL(KMccPrerollTime, packageBuffer );
       
   910         mccFileSource->SetParameterL(KMccPrerollTime, packageBuffer );
       
   911         }   
       
   912     }    
       
   913     
       
   914 // -----------------------------------------------------------------------------
       
   915 // MccCodecConfigurator::DoConfigureClipUplinkStreamL
       
   916 // Uplink/display codec configuration
       
   917 // -----------------------------------------------------------------------------
       
   918 void MccCodecConfigurator::DoConfigureClipUplinkStreamL( 
       
   919 	CPayloadFormatWrite& aFormatter, 
       
   920     const TMccCodecInfo& aCodec,
       
   921     MDataSink* aAssociatedSink,
       
   922     CMccRtpMediaClock& aClock )
       
   923     {
       
   924 	TMccCodecInfoBuffer buffer( aCodec );
       
   925     aFormatter.ConfigurePayloadFormatL( buffer, aClock );
       
   926     DoConfigureDisplayL( aCodec, aAssociatedSink );
       
   927     }
       
   928     
       
   929 // -----------------------------------------------------------------------------
       
   930 // MccCodecConfigurator::DoConfigureLiveVideoUplinkStreamL
       
   931 // Uplink/Record codec configuration
       
   932 // -----------------------------------------------------------------------------
       
   933 void MccCodecConfigurator::DoConfigureLiveVideoUplinkStreamL( 
       
   934     CMccVideoSource& aDataSource,
       
   935 	CPayloadFormatWrite& aFormatter, 
       
   936     const TMccCodecInfo& aCodec,
       
   937     MDataSink* aAssociatedSink,
       
   938     CMccRtpMediaClock& aClock )
       
   939     {
       
   940     DoConfigureCameraL( aDataSource, aCodec );
       
   941 	TMccCodecInfoBuffer buffer( aCodec );
       
   942     aFormatter.ConfigurePayloadFormatL( buffer, aClock );
       
   943     DoConfigureDisplayL( aCodec, aAssociatedSink );
       
   944     }
       
   945 
       
   946 // -----------------------------------------------------------------------------
       
   947 // MccCodecConfigurator::DoConfigureDtmfFormatL
       
   948 // Configures DTMF mediaformat plugin.
       
   949 // -----------------------------------------------------------------------------
       
   950 void MccCodecConfigurator::DoConfigureDtmfFormatL(
       
   951 	CPayloadFormatRead& aFormatDecoder,
       
   952     const TMccCodecInfo& aCodec )
       
   953     {
       
   954     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureDtmfFormatL, downlink" )
       
   955     
       
   956     CDTMFPayloadFormatRead& formatRead 
       
   957         = reinterpret_cast<CDTMFPayloadFormatRead&>( aFormatDecoder );
       
   958     
       
   959     const TMccCodecInfoBuffer buffer( aCodec );
       
   960     formatRead.ConfigurePayloadFormatL( buffer );
       
   961     formatRead.SetPayloadFormat( EDTMFPayloadFormatEvent );
       
   962     
       
   963     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureDtmfFormatL, exit" )
       
   964     }
       
   965 
       
   966 // -----------------------------------------------------------------------------
       
   967 // MccCodecConfigurator::DoConfigureDtmfFormatL
       
   968 // Configures DTMF mediaformat plugin.
       
   969 // -----------------------------------------------------------------------------
       
   970 void MccCodecConfigurator::DoConfigureDtmfFormatL(
       
   971     CPayloadFormatWrite& aFormatEncoder,
       
   972     const TMccCodecInfo& aCodec,
       
   973     CMccRtpMediaClock& aClock )
       
   974     {
       
   975     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureDtmfFormatL, uplink" )
       
   976     
       
   977     CDTMFPayloadFormatWrite& formatWrite
       
   978         = reinterpret_cast<CDTMFPayloadFormatWrite&>( aFormatEncoder );
       
   979     
       
   980     const TMccCodecInfoBuffer buffer( aCodec );
       
   981     formatWrite.ConfigurePayloadFormatL( buffer, aClock );
       
   982     formatWrite.NotifyStopInDTMFString( ETrue );
       
   983     formatWrite.SetPayloadFormat( EDTMFPayloadFormatEvent );
       
   984     
       
   985     __SUBCONTROLLER( "MccCodecConfigurator::DoConfigureDtmfFormatL, exit" )
       
   986     }
       
   987     
       
   988 // -----------------------------------------------------------------------------
       
   989 // MccCodecConfigurator::DoConfigureLiveVideoDownlinkStreamL
       
   990 // video Downlink codec configuration
       
   991 // -----------------------------------------------------------------------------  
       
   992 void MccCodecConfigurator::DoConfigureLiveVideoDownlinkStreamL(
       
   993 	MDataSink* aDataSink,
       
   994 	CPayloadFormatRead& aFormatter,
       
   995 	const TMccCodecInfo& aCodec )
       
   996 	{              
       
   997     TMccCodecInfoBuffer buffer( aCodec );
       
   998     aFormatter.ConfigurePayloadFormatL( buffer );
       
   999     DoConfigureDisplayL( aCodec, aDataSink );
       
  1000 	}
       
  1001     
       
  1002         
       
  1003 // -----------------------------------------------------------------------------
       
  1004 // MccCodecConfigurator::GetCodecDefaultsL
       
  1005 // Uplink/Record codec configuration
       
  1006 // -----------------------------------------------------------------------------
       
  1007 void MccCodecConfigurator::GetCodecDefaultsL( 
       
  1008     const TUid aType,
       
  1009     TDes8& aParam, 
       
  1010     TMccCodecInfo& aCodec )
       
  1011 	{
       
  1012     if( KMccVideoSourceUid == aType )
       
  1013         {
       
  1014 	    DoGetCameraConfigurationL( aCodec, aParam );			
       
  1015         }
       
  1016     else if( KMccFileSourceUid == aType )
       
  1017         {
       
  1018 	    DoGetClipConfigurationL( aParam );			
       
  1019         }
       
  1020     else
       
  1021         {
       
  1022         }
       
  1023 	}
       
  1024 
       
  1025 // -----------------------------------------------------------------------------
       
  1026 // MccCodecConfigurator::ChangeBitrateL
       
  1027 // Changes the current codec bitrate
       
  1028 // -----------------------------------------------------------------------------
       
  1029 //
       
  1030 void MccCodecConfigurator::ChangeBitrateL( 
       
  1031     const TMccCodecInfo& aCodec,
       
  1032     TUint aBitrate, 
       
  1033     CMMFDevSound& aSounddevice )
       
  1034     {
       
  1035     __SUBCONTROLLER( "MccCodecConfigurator::ChangeBitrateL" )
       
  1036     
       
  1037     // Create an instance of speech encoder config custom interface
       
  1038     CSpeechEncoderConfig* speechEncConfIf = 
       
  1039             CSpeechEncoderConfig::NewL( aSounddevice );
       
  1040     
       
  1041     CleanupStack::PushL( speechEncConfIf );
       
  1042     
       
  1043     // Only AMR supports bitrate change dynamically
       
  1044     TFourCC fourcc( aCodec.iFourCC );
       
  1045     const TUint32 fourccVal = fourcc.FourCC();
       
  1046     if ( KMccFourCCIdAMRNB == fourccVal && IsSupportedAmrNbBitrate( aBitrate ) )
       
  1047         {
       
  1048         __SUBCONTROLLER_INT1( 
       
  1049             "MccCodecConfigurator::ChangeBitrateL, setting amr nb bitrate:", 
       
  1050             aBitrate )
       
  1051             
       
  1052         User::LeaveIfError( speechEncConfIf->SetBitrate( aBitrate ) );
       
  1053         }
       
  1054     else if ( KMccFourCCIdAMRWB == fourccVal && IsSupportedAmrWbBitrate( aBitrate ) )
       
  1055         {
       
  1056         __SUBCONTROLLER_INT1( 
       
  1057             "MccCodecConfigurator::ChangeBitrateL, setting amr wb bitrate:", 
       
  1058             aBitrate )
       
  1059             
       
  1060         User::LeaveIfError( speechEncConfIf->SetBitrate( aBitrate ) );
       
  1061         }
       
  1062     else
       
  1063         {
       
  1064         __SUBCONTROLLER( "MccCodecConfigurator::ChangeBitrateL, bitrate not supported!" )
       
  1065         User::Leave( KErrNotSupported );
       
  1066         }
       
  1067 
       
  1068     CleanupStack::PopAndDestroy( speechEncConfIf );
       
  1069     
       
  1070     __SUBCONTROLLER( "MccCodecConfigurator::ChangeBitrateL, exit" )
       
  1071     }
       
  1072 
       
  1073 // -----------------------------------------------------------------------------
       
  1074 // MccCodecConfigurator::ConvertBoolean
       
  1075 // Converts possibly dirty boolean parameter to EFalse/ETrue 
       
  1076 // -----------------------------------------------------------------------------
       
  1077 //
       
  1078 TBool MccCodecConfigurator::ConvertBoolean( TBool aParam )
       
  1079     {
       
  1080     // As VoIP settings may contain negative values (-1 especially) for marking
       
  1081     // the setting as "Not set", we need to convert it into a real Symbian
       
  1082     // style ETrue/EFalse boolean. Especially in -1 param cases, we want to
       
  1083     // convert it into EFalse.
       
  1084     if( aParam > 0 )
       
  1085         {    
       
  1086         return ETrue;
       
  1087         }
       
  1088     else
       
  1089         {
       
  1090         return EFalse;
       
  1091         }
       
  1092     }
       
  1093 
       
  1094 // -----------------------------------------------------------------------------
       
  1095 // MccCodecConfigurator::IsSupportedAmrNbBitrate
       
  1096 // -----------------------------------------------------------------------------        
       
  1097 TBool MccCodecConfigurator::IsSupportedAmrNbBitrate( TInt aBitrate )
       
  1098     {
       
  1099     return ( aBitrate == KAmrNbBitrate475 ||
       
  1100              aBitrate == KAmrNbBitrate515 ||
       
  1101              aBitrate == KAmrNbBitrate590 ||
       
  1102              aBitrate == KAmrNbBitrate670 ||
       
  1103              aBitrate == KAmrNbBitrate740 ||
       
  1104              aBitrate == KAmrNbBitrate795 ||
       
  1105              aBitrate == KAmrNbBitrate102 ||
       
  1106              aBitrate == KAmrNbBitrate122 );
       
  1107     }
       
  1108 
       
  1109 // -----------------------------------------------------------------------------
       
  1110 // MccCodecConfigurator::IsSupportedAmrWbBitrate
       
  1111 // -----------------------------------------------------------------------------
       
  1112 TBool MccCodecConfigurator::IsSupportedAmrWbBitrate( TInt aBitrate )
       
  1113     {
       
  1114     return ( aBitrate == KAmrWbBitrate660 ||
       
  1115              aBitrate == KAmrWbBitrate885 ||
       
  1116              aBitrate == KAmrWbBitrate1265 ||
       
  1117              aBitrate == KAmrWbBitrate1425 ||
       
  1118              aBitrate == KAmrWbBitrate1585 ||
       
  1119              aBitrate == KAmrWbBitrate1825 ||
       
  1120              aBitrate == KAmrWbBitrate1985 ||
       
  1121              aBitrate == KAmrWbBitrate2305 ||
       
  1122              aBitrate == KAmrWbBitrate2385 );
       
  1123     }
       
  1124 
       
  1125 // -----------------------------------------------------------------------------
       
  1126 // MccCodecConfigurator::IlbcNeedsStopResume
       
  1127 // -----------------------------------------------------------------------------
       
  1128 TBool MccCodecConfigurator::IlbcNeedsStopResume( TInt aOrigBitrate,
       
  1129     TInt aRequBitrate, const TFourCC& aCodec )
       
  1130     {
       
  1131     const TFourCC tmp( KMccFourCCIdILBC );
       
  1132     if ( tmp == aCodec && aOrigBitrate != aRequBitrate )
       
  1133         {
       
  1134         __SUBCONTROLLER( "MccCodecConfigurator::IlbcNeedsStopResume ETrue" )
       
  1135         
       
  1136         return ETrue;
       
  1137         }
       
  1138     else
       
  1139         {
       
  1140         __SUBCONTROLLER( "MccCodecConfigurator::IlbcNeedsStopResume EFalse" )
       
  1141         
       
  1142         return EFalse;
       
  1143         }
       
  1144     }
       
  1145 
       
  1146 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  1147 
       
  1148 //  End of File