mmsharing/mmshengine/src/musengmcesession.cpp
changeset 22 496ad160a278
child 25 53c1c4459a94
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     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 // USER
       
    20 #include "mussettings.h"
       
    21 #include "musengmcesession.h"
       
    22 #include "musengsessiondurationtimer.h"
       
    23 #include "musengmceutils.h"
       
    24 #include "musuid.hrh"
       
    25 #include "musenglogger.h"
       
    26 #include "mussipprofilehandler.h"
       
    27 #include "mussessionproperties.h"
       
    28 #include "musenguriparser.h"
       
    29 #include "musengtelephoneutils.h"
       
    30 
       
    31 // SYSTEM
       
    32 #include <lcsessionobserver.h>
       
    33 #include <lcuiprovider.h>
       
    34 #include <lcvideoplayer.h>
       
    35 #include <mcedefs.h>
       
    36 #include <mcemanager.h>
       
    37 #include <mceinsession.h>
       
    38 #include <mcevideostream.h>
       
    39 #include <mceaudiostream.h>
       
    40 #include <mcertpsink.h>
       
    41 #include <mcedisplaysink.h>
       
    42 #include <mcespeakersink.h>
       
    43 #include <mcefilesource.h>
       
    44 #include <mcecamerasource.h>
       
    45 #include <mcertpsource.h>
       
    46 #include <mceaudiocodec.h>
       
    47 #include <mceavccodec.h>
       
    48 #include <AudioPreference.h>
       
    49 #include <e32property.h>
       
    50 #include <cntitem.h>
       
    51 #include <cntfield.h>
       
    52 #include <cntdef.h>
       
    53 #include <cntfldst.h>
       
    54 
       
    55 
       
    56 const TInt KMusEngTimerInterval = 1000000; // 1 second
       
    57 const TInt KMusEngRtcpInactivityThreshold = 20; // seconds
       
    58 const TInt KMusEngArrayGranularity3 = 3;
       
    59 
       
    60 const TInt KMusEngSipReasonCodeOk = 200;
       
    61 const TInt KMusEngSipReasonCodeBusyHere = 486;
       
    62 _LIT8( KMusEngSipReasonPhraseBusyHere, "Busy Here" );
       
    63 _LIT8( KMusEngSipReasonPhraseBusy, "Busy" );
       
    64 
       
    65 const TUint KMusEngDedicatedVideoPort = 49152;
       
    66 const TUint KMusEngDedicatedAudioPort = 57344;
       
    67 
       
    68 #define MUS_CODEC_ARR_CONST_CAST( codecArr ) \
       
    69 ( const_cast< RPointerArray< CMceVideoCodec >& >( codecArr ) )
       
    70 
       
    71 // Names of AVC levels in string for config keys stored in CenRep 
       
    72 _LIT8( KMusAvcBitrateLevel1, "AvcBrL1=" );
       
    73 _LIT8( KMusAvcBitrateLevel1b, "AvcBrL1b=" );
       
    74 _LIT8( KMusAvcBitrateLevel1_1, "AvcBrL1_1=" );
       
    75 _LIT8( KMusAvcBitrateLevel1_2, "AvcBrL1_2=" );
       
    76 _LIT8( KMusAvcBitrateLevel1_3, "AvcBrL1_3=" );
       
    77 _LIT8( KMusAvcBitrateLevel2, "AvcBrL2=" );
       
    78 
       
    79 _LIT8( KMusEncoderInfoTokenizer, ";" );
       
    80 
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CMusEngMceSession::CMusEngMceSession()
       
    87     : iSecondsFromLastRtcpReport ( 0 ),
       
    88       // Although speaker is constructed as muted, it is not explicitly muted
       
    89       iExplicitlyMuted( EFalse ),
       
    90       iBackground( ETrue )
       
    91     {
       
    92     iMceManagerUid.iUid = KMusUiUid;
       
    93     iBackground = IsBackgroundStartup();
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CMusEngMceSession::ConstructL()
       
   101     {
       
   102     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::ConstructL()" )
       
   103     
       
   104     iTelephoneUtils = CMusEngTelephoneUtils::NewL( *this );
       
   105 
       
   106     // Creating new MCE Manager and set all needed observers to this class.
       
   107     iManager = CMceManager::NewL( iMceManagerUid,
       
   108                                   &iTransactionDataContainer );
       
   109     iManager->SetSessionObserver( this );
       
   110     iManager->SetInSessionObserver( this );
       
   111     iManager->SetMediaObserver( this );
       
   112     iManager->SetRtpObserver( this );
       
   113 
       
   114     // Check if operator specific behavior is expected
       
   115     iOperatorVariant = ( MultimediaSharingSettings::OperatorVariantSettingL() ==
       
   116                          MusSettingsKeys::EOperatorSpecific );
       
   117     
       
   118     // Update timer initialization
       
   119     iUpdateTimer = CMusEngSessionDurationTimer::NewL( *this );
       
   120     
       
   121     iSipProfileHandler = CMusSipProfileHandler::NewL( *this );
       
   122     
       
   123     iRemoteDetails = HBufC::NewL( RProperty::KMaxPropertySize );
       
   124     iRemoteDetails->Des().Copy( KNullDesC );
       
   125     
       
   126     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::ConstructL()" )
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 CMusEngMceSession::~CMusEngMceSession()
       
   134     {
       
   135     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::~CMusEngMceSession()" )
       
   136     
       
   137     delete iSipProfileHandler;
       
   138     delete iSession;
       
   139     delete iManager;
       
   140     delete iUpdateTimer;
       
   141     delete iTelephoneUtils;
       
   142     delete iRemoteDetails;
       
   143     
       
   144     RProperty::Set( NMusSessionApi::KCategoryUid, 
       
   145                     NMusSessionApi::KFastMode, 
       
   146                     MusSettingsKeys::EFastModeDisabled );
       
   147     
       
   148     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::~CMusEngMceSession()" )
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // From MMusEngDisplayHandler
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 TRect CMusEngMceSession::Rect() const
       
   156     {
       
   157     MUS_LOG( "mus: [ENGINE]  CMusEngMceSession::Rect()" )
       
   158     return iRect;
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // From MMusEngDisplayHandler
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CMusEngMceSession::SetRectL( const TRect& aRect )
       
   166     {
       
   167     MUS_LOG( "mus: [ENGINE]  CMusEngSession::SetRectL()" )
       
   168     iRect = aRect;
       
   169     RectChangedL();
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // From MMusEngDisplayHandler
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CMusEngMceSession::SetSecondaryRectL( const TRect& aSecondaryRect )
       
   177     {
       
   178     MUS_LOG( "mus: [ENGINE]  CMusEngMceSession::SetSecondaryRectL()" )
       
   179     
       
   180     // Same rect is set by primary and secondary setters
       
   181     iRect = aSecondaryRect;
       
   182     RectChangedL();
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // From MMusEngDisplayHandler
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 TRect CMusEngMceSession::SecondaryRect() const
       
   190     {
       
   191     MUS_LOG( "mus: [ENGINE]  CMusEngMceSession::SecondaryRect()" )
       
   192     return iRect;
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // From MMusEngDisplayHandler
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 MMusEngDisplayHandler::TDisplayOrientation CMusEngMceSession::OrientationL()
       
   200     {
       
   201     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::RotationL()" )
       
   202     
       
   203     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   204     
       
   205     CMceDisplaySink* display = MusEngMceUtils::GetDisplayL( *iSession );
       
   206     
       
   207     TDisplayOrientation displayOrientation;
       
   208     CMceDisplaySink::TRotation rotation( display->RotationL() );
       
   209     
       
   210     MUS_LOG1( "mus: [ENGINE]     MCE rotation is %d", rotation )
       
   211     
       
   212     if ( rotation == CMceDisplaySink::ENone )
       
   213         {
       
   214         displayOrientation = CMusEngMceSession::EPortrait;
       
   215         }
       
   216     else
       
   217         {
       
   218         displayOrientation = CMusEngMceSession::ELandscape;
       
   219         }
       
   220     
       
   221     MUS_LOG1( "mus: [ENGINE]  <- CMusEngMceSession::RotationL() %d", 
       
   222               displayOrientation )
       
   223     
       
   224     return displayOrientation;
       
   225     }
       
   226 
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 // -----------------------------------------------------------------------------
       
   231 //        
       
   232 void CMusEngMceSession::SetOrientationL( TDisplayOrientation aOrientation )
       
   233     {
       
   234     MUS_LOG1( "mus: [ENGINE]  -> CMusEngMceSession::SetOrientationL() %d", 
       
   235               aOrientation )
       
   236               
       
   237     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   238     
       
   239     CMceDisplaySink* display = MusEngMceUtils::GetDisplayL( *iSession );
       
   240 
       
   241     if ( aOrientation == EPortrait )
       
   242         {
       
   243         display->SetRotationL( CMceDisplaySink::ENone );
       
   244         }
       
   245     else
       
   246         {
       
   247         display->SetRotationL( CMceDisplaySink::EClockwise90Degree );
       
   248         }
       
   249 
       
   250     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::SetOrientationL()" )
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // 
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CMusEngMceSession::EnableDisplayL( TBool aEnable )
       
   258     {
       
   259     MUS_LOG1( "mus: [ENGINE]     -> CMusEngMceSession::EnableDisplay() %d", 
       
   260               aEnable )
       
   261 
       
   262     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   263 
       
   264     CMceDisplaySink* display = MusEngMceUtils::GetDisplayL( *iSession );
       
   265     
       
   266     if ( aEnable )
       
   267         {
       
   268         if ( !display->IsEnabled() )
       
   269             {
       
   270             display->EnableL();
       
   271             MUS_LOG( "                  Display enabled" )
       
   272             if ( !iExplicitlyMuted )
       
   273                 {
       
   274                 // Since speaker is not explicitly muted, but disabled as
       
   275                 // a consequence of disabling bundled display, it must be
       
   276                 // unmuted.
       
   277                 DoMuteSpeakerL( EFalse );
       
   278                 MUS_LOG( "                  Bundled speaker enabled" )
       
   279                 }
       
   280             }
       
   281         else
       
   282             {
       
   283             MUS_LOG( "                  Display already enabled, ignore" )
       
   284             }
       
   285         }
       
   286     else
       
   287         {
       
   288         if ( display->IsEnabled() )
       
   289             {
       
   290             display->DisableL();
       
   291             MUS_LOG( "                  Display disabled" )
       
   292             if ( !iExplicitlyMuted )
       
   293                 {
       
   294                 // Speaker will not be explicitly muted, but disabled as
       
   295                 // a consequence of disabling bundled display.
       
   296                 DoMuteSpeakerL( ETrue );
       
   297                 MUS_LOG( "                  Bundled speaker disabled" )
       
   298                 }
       
   299             }
       
   300         else
       
   301             {
       
   302             MUS_LOG( "                  Display already disabled, ignore" )
       
   303             }
       
   304         }
       
   305       
       
   306         
       
   307     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::EnableDisplay()")
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // 
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 TBool CMusEngMceSession::IsDisplayEnabled()
       
   315     {
       
   316     TBool enabled( EFalse );
       
   317     if ( iSession )
       
   318         {
       
   319         CMceDisplaySink* display = 
       
   320            MusEngMceUtils::GetDisplay( *iSession, ETrue );
       
   321         if ( display )
       
   322            {
       
   323            enabled = display->IsEnabled();
       
   324            }
       
   325         }
       
   326     return enabled;
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // From MMusEngDisplayHandler
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 TBool CMusEngMceSession::IsDisplayActive()
       
   334     {
       
   335     return ( IsDisplayEnabled() );
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // From MMusEngAudioRoutingObserver
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 void CMusEngMceSession::AudioRoutingChanged()
       
   343     {
       
   344     InformObserverAboutPlayerUpdate( LocalVideoPlayer() );
       
   345     InformObserverAboutPlayerUpdate( RemoteVideoPlayer() );
       
   346     }
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // From MLcSession 
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 MLcSession::TLcSessionState CMusEngMceSession::LcSessionState() const
       
   353     {
       
   354     TLcSessionState lcSessionState = MLcSession::EUninitialized;
       
   355 
       
   356     if ( iSession )
       
   357         {
       
   358         switch( iSession->State() )
       
   359             {
       
   360             case CMceSession::EIdle: 
       
   361                 {
       
   362                 lcSessionState = MLcSession::EInitialized;
       
   363                 break;
       
   364                 }
       
   365             case CMceSession::EIncoming:
       
   366             case CMceSession::EProceeding:
       
   367             case CMceSession::EReserving:
       
   368                 {
       
   369                 lcSessionState = MLcSession::EReceived;
       
   370                 break;
       
   371                 }
       
   372             
       
   373             case CMceSession::EOffering:
       
   374             case CMceSession::EAnswering:
       
   375                 {
       
   376                 lcSessionState = MLcSession::EOpening;
       
   377                 break;
       
   378                 }
       
   379             case CMceSession::EEstablished:
       
   380                 {
       
   381                 lcSessionState = MLcSession::EOpen;
       
   382                 break;
       
   383                 }
       
   384             case CMceSession::ECancelling:
       
   385             case CMceSession::ETerminating:
       
   386                 {
       
   387                 lcSessionState = MLcSession::EClosing;
       
   388                 break;
       
   389                 }
       
   390             case CMceSession::ETerminated:
       
   391                 {
       
   392                 lcSessionState = MLcSession::EClosed;
       
   393                 break;
       
   394                 }
       
   395             default:
       
   396                {
       
   397                lcSessionState = MLcSession::EUninitialized;
       
   398                break;
       
   399                }
       
   400             }
       
   401         }
       
   402     return  lcSessionState;
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // From MLcSession
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 void CMusEngMceSession::SetLcSessionObserver( MLcSessionObserver* aObserver )
       
   410     {
       
   411     iLcSessionObserver = aObserver;
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // From MLcSession
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CMusEngMceSession::SetLcUiProvider( MLcUiProvider* aUiProvider )
       
   419     {
       
   420     iLcUiProvider = aUiProvider;
       
   421     }
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // From MLcSession
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 MLcVideoPlayer* CMusEngMceSession::RemoteVideoPlayer()
       
   428     {
       
   429     return NULL;
       
   430     }
       
   431 
       
   432 // -----------------------------------------------------------------------------
       
   433 // From MLcSession
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 MLcVideoPlayer* CMusEngMceSession::LocalVideoPlayer()
       
   437     {
       
   438     return NULL;
       
   439     }
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // From MLcSession
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 const TDesC& CMusEngMceSession::LocalDisplayName()
       
   446     {
       
   447     return KNullDesC;
       
   448     }
       
   449 
       
   450 // -----------------------------------------------------------------------------
       
   451 // From MLcSession
       
   452 // -----------------------------------------------------------------------------
       
   453 //
       
   454 const TDesC& CMusEngMceSession::RemoteDisplayName()
       
   455     {
       
   456     return KNullDesC;
       
   457     }
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // From MLcSession
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 TInt CMusEngMceSession::SetParameter( TInt /*aId*/, TInt /*aValue*/ )
       
   464     {
       
   465     return KErrNotSupported;
       
   466     }
       
   467 
       
   468 // -----------------------------------------------------------------------------
       
   469 // From MLcSession
       
   470 // -----------------------------------------------------------------------------
       
   471 //
       
   472 TInt CMusEngMceSession::ParameterValue( TInt /*aId*/ )
       
   473     {
       
   474     return KErrNotSupported;
       
   475     }
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // From MLcSession
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 TBool CMusEngMceSession::IsBackgroundStartup()
       
   482     {
       
   483     TInt fastMode;
       
   484     TInt error = RProperty::Get( NMusSessionApi::KCategoryUid, 
       
   485                                  NMusSessionApi::KFastMode, 
       
   486                                  fastMode );
       
   487     
       
   488     return ( error == KErrNone && 
       
   489              iBackground &&
       
   490              fastMode == MusSettingsKeys::EFastModeOn );
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // From MLcSession
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 TInt CMusEngMceSession::SetForegroundStatus( TBool aIsForeground )
       
   498     {
       
   499     MUS_LOG1( "mus: [ENGINE]     -> CMusEngMceSession::SetForegroundStatus() %d", 
       
   500               aIsForeground )
       
   501 
       
   502     if ( aIsForeground )
       
   503         {
       
   504         // Only clear the bg info, do not ever enable it again
       
   505         iBackground = EFalse;
       
   506         }
       
   507     
       
   508     return KErrNone;
       
   509     }
       
   510  
       
   511 // -----------------------------------------------------------------------------
       
   512 // From MLcSession
       
   513 // -----------------------------------------------------------------------------
       
   514 //   
       
   515 const TDesC& CMusEngMceSession::RemoteDetails()
       
   516     {
       
   517     // Don't care about error, empty value will be used in that case
       
   518     TPtr ptrDetails( iRemoteDetails->Des() );
       
   519     RProperty::Get( NMusSessionApi::KCategoryUid,
       
   520                     NMusSessionApi::KTelNumber,
       
   521                     ptrDetails ); 
       
   522     return *iRemoteDetails;
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // From MLcSession
       
   527 // -----------------------------------------------------------------------------
       
   528 //   
       
   529 void CMusEngMceSession::UpdateLcSessionL()
       
   530     {
       
   531     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   532         
       
   533     //In Mus engine, every update of player has immediate effect. Thus, this method
       
   534     //is empty.
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // From MLcSession
       
   539 // -----------------------------------------------------------------------------
       
   540 //
       
   541 TBool CMusEngMceSession::SendDialTone( TChar aKey)
       
   542     {
       
   543     MUS_LOG1( "mus: [ENGINE]     -> CMusEngMceSession::SendDialTone() %c", 
       
   544                  aKey )
       
   545     return ETrue;
       
   546     }
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // From MLcAudioControl
       
   550 // -----------------------------------------------------------------------------
       
   551 //
       
   552 TBool CMusEngMceSession::IsLcAudioMutedL()
       
   553     {
       
   554     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   555               
       
   556     TBool containsAudio( EFalse );
       
   557     for ( TInt i = 0; i < iSession->Streams().Count(); ++i )
       
   558         {
       
   559         if ( iSession->Streams()[i]->Type() == KMceAudio )
       
   560             {
       
   561             containsAudio = ETrue;
       
   562             }
       
   563         }    
       
   564     
       
   565     if ( containsAudio && !iExplicitlyMuted )
       
   566         {
       
   567         return EFalse;
       
   568         }
       
   569     
       
   570     return ETrue;
       
   571     }
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // From MLcAudioControl
       
   575 // -----------------------------------------------------------------------------
       
   576 //
       
   577 void CMusEngMceSession::MuteLcAudioL( TBool aMute )
       
   578     {
       
   579     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   580     
       
   581     DoMuteSpeakerL( aMute );
       
   582     iExplicitlyMuted = aMute;
       
   583     }
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // From MLcAudioControl
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 TBool CMusEngMceSession::IsLcMicMutedL()
       
   590     {
       
   591     return iTelephoneUtils->IsMicMutedL();
       
   592     }
       
   593 
       
   594 // -----------------------------------------------------------------------------
       
   595 // From MLcAudioControl
       
   596 // -----------------------------------------------------------------------------
       
   597 //
       
   598 void CMusEngMceSession::MuteLcMicL( TBool aMute )
       
   599     {
       
   600     iTelephoneUtils->MuteMicL( aMute );
       
   601     }
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // From MLcAudioControl
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 TBool CMusEngMceSession::IsEnablingLcLoudspeakerAllowed()
       
   608     {
       
   609     return iTelephoneUtils->AudioRoutingCanBeChanged();
       
   610     }
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // From MLcAudioControl
       
   614 // -----------------------------------------------------------------------------
       
   615 //
       
   616 void CMusEngMceSession::EnableLcLoudspeakerL( TBool aEnabled )
       
   617     {
       
   618     TRAPD( error, iTelephoneUtils->LoudspeakerL( aEnabled ) )
       
   619 
       
   620     if ( error != KErrNone )
       
   621         {
       
   622         // This is writed for emulator use
       
   623         if ( error != KErrNotSupported )
       
   624             {
       
   625             MUS_LOG1( "mus: [ENGINE] CMusEngSession::EnableLoudspeakerL() Leave: #%d",
       
   626                       error )
       
   627             User::Leave( error );
       
   628             }
       
   629         // Not leave in emulator if KErrNotSupported
       
   630         #if (!defined (__WINS__) && !defined(__WINSCW__))
       
   631         User::Leave( error );
       
   632         #endif
       
   633         }
       
   634     }
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // From MLcAudioControl
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 TBool CMusEngMceSession::IsLcLoudspeakerEnabled()
       
   641     {
       
   642     return iTelephoneUtils->IsLoudSpeakerEnabled();
       
   643     }
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // From MLcAudioControl
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 TInt CMusEngMceSession::LcVolumeL()
       
   650     {
       
   651     return iTelephoneUtils->GetVolumeL();
       
   652     }
       
   653 
       
   654 // -----------------------------------------------------------------------------
       
   655 // From MLcAudioControl
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 void CMusEngMceSession::SetLcVolumeL( TInt aValue )
       
   659     {
       
   660     iTelephoneUtils->SetVolumeL( aValue );
       
   661     }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // From MLcAudioControl
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 void CMusEngMceSession::IncreaseLcVolumeL()
       
   668     {
       
   669     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   670 
       
   671     TInt currentVolume = iTelephoneUtils->GetVolumeL();
       
   672     iTelephoneUtils->SetVolumeL( currentVolume  + 1 );
       
   673     SetSpeakerVolumeL( LcVolumeL() );
       
   674     }
       
   675 
       
   676 // -----------------------------------------------------------------------------
       
   677 // From MLcAudioControl
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 void CMusEngMceSession::DecreaseLcVolumeL()
       
   681     {
       
   682     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   683 
       
   684     TInt currentVolume = iTelephoneUtils->GetVolumeL();
       
   685     iTelephoneUtils->SetVolumeL( currentVolume - 1 );
       
   686     SetSpeakerVolumeL( LcVolumeL() );
       
   687     }
       
   688 
       
   689 // -----------------------------------------------------------------------------
       
   690 //
       
   691 // -----------------------------------------------------------------------------
       
   692 //
       
   693 MLcSessionObserver* CMusEngMceSession::LcSessionObserver()
       
   694     {
       
   695     return iLcSessionObserver;
       
   696     }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 //
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 MLcUiProvider* CMusEngMceSession::LcUiProvider()
       
   703     {
       
   704     return iLcUiProvider;
       
   705     }
       
   706 
       
   707 // -----------------------------------------------------------------------------
       
   708 // Returns estabilished session time. If not established return
       
   709 // value is < 0
       
   710 // -----------------------------------------------------------------------------
       
   711 //
       
   712 TTimeIntervalSeconds CMusEngMceSession::GetSessionTime() const
       
   713     {
       
   714     if ( iSession && iSession->State() == CMceSession::EEstablished )
       
   715         {
       
   716         TTime time;
       
   717         TTimeIntervalSeconds seconds;
       
   718         time.HomeTime();
       
   719 
       
   720         time.SecondsFrom( iStartTime, seconds );
       
   721 
       
   722         return seconds;
       
   723         }
       
   724 
       
   725     return TTimeIntervalSeconds( KErrNotReady );
       
   726     }
       
   727 
       
   728 // -----------------------------------------------------------------------------
       
   729 //
       
   730 // -----------------------------------------------------------------------------
       
   731 //
       
   732 void CMusEngMceSession::RectChangedL()
       
   733     {
       
   734     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::RectChangedL()" )
       
   735 
       
   736     // If session is not yet created, do nothing
       
   737     if ( iSession && iSession->State() != CMceSession::ETerminated )
       
   738         {
       
   739         // Rely on having just one display
       
   740         CMceDisplaySink* display = MusEngMceUtils::GetDisplayL( *iSession );
       
   741         display->SetDisplayRectL( Rect() );
       
   742         }
       
   743 
       
   744     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::RectChangedL()" )
       
   745     }
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 //
       
   749 // -----------------------------------------------------------------------------
       
   750 //
       
   751 void CMusEngMceSession::InformObserverAboutSessionStateChange()
       
   752     {
       
   753     if ( iLcSessionObserver )
       
   754         {
       
   755         iLcSessionObserver->StateChanged( *this );
       
   756         }
       
   757     }
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 //
       
   761 // -----------------------------------------------------------------------------
       
   762 //
       
   763 void CMusEngMceSession::InformObserverAboutSessionUpdate()
       
   764     {
       
   765     if ( iLcSessionObserver )
       
   766         {
       
   767         iLcSessionObserver->Updated( *this );
       
   768         }
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 //
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 void CMusEngMceSession::InformObserverAboutSessionFailure( TInt aReason )
       
   776     {
       
   777     if ( iLcSessionObserver )
       
   778         {
       
   779         iLcSessionObserver->Failed( *this, aReason );
       
   780         }
       
   781     }
       
   782 
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 // -----------------------------------------------------------------------------
       
   786 //
       
   787 void CMusEngMceSession::InformObserverAboutPlayerStateChange( 
       
   788     MLcVideoPlayer* aPlayer )
       
   789     {
       
   790     if ( iLcSessionObserver && aPlayer )
       
   791         {
       
   792         iLcSessionObserver->StateChanged( *aPlayer );
       
   793         }
       
   794     
       
   795     }
       
   796 
       
   797 // -----------------------------------------------------------------------------
       
   798 //
       
   799 // -----------------------------------------------------------------------------
       
   800 //
       
   801 void CMusEngMceSession::InformUiProviderAboutReceivingStart()
       
   802     {
       
   803     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::InformUiProviderAboutReceivingStart()" )
       
   804     if ( iBackground && iLcUiProvider )
       
   805         {
       
   806         MUS_LOG( "mus: [ENGINE]     receiving started in BG mode, switching to FG" )
       
   807         iLcUiProvider->HandleForegroundStatus( ETrue );
       
   808         }
       
   809     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::InformUiProviderAboutReceivingStart()" )
       
   810     }
       
   811 
       
   812 // -----------------------------------------------------------------------------
       
   813 //
       
   814 // -----------------------------------------------------------------------------
       
   815 //
       
   816 void CMusEngMceSession::InformObserverAboutPlayerUpdate( 
       
   817     MLcVideoPlayer* aPlayer )
       
   818     {
       
   819     if ( iLcSessionObserver && aPlayer )
       
   820         {
       
   821         iLcSessionObserver->Updated( *aPlayer );
       
   822         }
       
   823     }
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 //
       
   827 // -----------------------------------------------------------------------------
       
   828 //
       
   829 void CMusEngMceSession::InformObserverAboutPlayerFailure( 
       
   830     MLcVideoPlayer* aPlayer, 
       
   831     TInt aReason )
       
   832     {
       
   833     if ( iLcSessionObserver && aPlayer )
       
   834         {
       
   835         iLcSessionObserver->Failed( *aPlayer, aReason );
       
   836         }
       
   837     }
       
   838 
       
   839 // -----------------------------------------------------------------------------
       
   840 //
       
   841 // -----------------------------------------------------------------------------
       
   842 //
       
   843 MLcUiProvider& CMusEngMceSession::LcUiProviderL()
       
   844     {
       
   845     __ASSERT_ALWAYS( iLcUiProvider, User::Leave( KErrNotReady ) );
       
   846     return *iLcUiProvider;
       
   847     }
       
   848 
       
   849 // -----------------------------------------------------------------------------
       
   850 //
       
   851 // -----------------------------------------------------------------------------
       
   852 //
       
   853 void CMusEngMceSession::AddSdpBandwidthAttributesL( CDesC8Array& aSdpLinesArray,
       
   854                                                     TInt aBandwidthAs )
       
   855     {
       
   856     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::AddSdpBandwidthAttributesL()" )
       
   857     const TInt KMusNumberMaxLength = 10;
       
   858     HBufC8* bandwidth = HBufC8::NewLC( 
       
   859             KMusEngSessionSdpLineTiasLine().Length() + KMusNumberMaxLength );
       
   860     
       
   861     bandwidth->Des().Copy( KMusEngSessionSdpLineBandwidthLine() );
       
   862     bandwidth->Des().AppendNum( aBandwidthAs );
       
   863     bandwidth->Des().Append( KMusEngNewLine() );
       
   864     aSdpLinesArray.AppendL( *bandwidth );
       
   865     
       
   866     bandwidth->Des().Copy( KMusEngSessionSdpLineTiasLine() );
       
   867     bandwidth->Des().AppendNum( aBandwidthAs * KMusTiasMultiplier );
       
   868     bandwidth->Des().Append( KMusEngNewLine() );
       
   869     aSdpLinesArray.AppendL( *bandwidth );
       
   870     
       
   871     CleanupStack::PopAndDestroy( bandwidth );  
       
   872     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::AddSdpBandwidthAttributesL()" )
       
   873     }
       
   874 
       
   875 // -----------------------------------------------------------------------------
       
   876 //
       
   877 // -----------------------------------------------------------------------------
       
   878 //
       
   879 TBool CMusEngMceSession::IsBandwidthAttributeSet( MDesC8Array* aSdpLinesArray )
       
   880     {
       
   881     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::IsBandwidthAttributeSet()" )
       
   882     TBool ret =
       
   883         ContainsText( aSdpLinesArray, KMusEngSessionSdpLineTiasLine() ) ||
       
   884         ContainsText( aSdpLinesArray, KMusEngSessionSdpLineBandwidthLine() );
       
   885     MUS_LOG1( "mus: [ENGINE]  <- CMusEngMceSession::IsBandwidthAttributeSet(): %d",
       
   886             ret )
       
   887     return ret;
       
   888     }
       
   889 
       
   890 // -----------------------------------------------------------------------------
       
   891 // Setting session level sdp lines. Bandwith attribute is always used in
       
   892 // operator variant mode and at receiver side (using force) when TIAS
       
   893 // usage is disabled. However, bandwidth attribute is preferred to be used 
       
   894 // at media level (see SetMediaSdpLinesL method). It is set to session level
       
   895 // only if other side is using also session level bandwidth. Media level
       
   896 // preference exists because some other manufacturer's videosharing does not
       
   897 // understand session level bandwidth attribute.
       
   898 // In non-operator variant mode and when TIAS usage is enabled, both AS and 
       
   899 // TIAS are added to session level only if the other side is using session 
       
   900 // level bandwidth.
       
   901 // -----------------------------------------------------------------------------
       
   902 //
       
   903 void CMusEngMceSession::SetSessionSdpLinesL( 
       
   904     CMceSession& aSession, 
       
   905     TBool aForceBandwidthLine )
       
   906     {
       
   907     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::SetSessionSdpLinesL()" )
       
   908     
       
   909     MDesC8Array* oldSessionSdpLines = aSession.SessionSDPLinesL();
       
   910     CleanupDeletePushL( oldSessionSdpLines );
       
   911     TBool bandwidthAtSessionLevel( ContainsText( oldSessionSdpLines, 
       
   912                                    KMusEngSessionSdpLineBandwidthLine() ) );
       
   913     TBool tiasAtSessionLevel( ContainsText( oldSessionSdpLines, 
       
   914                                    KMusEngSessionSdpLineTiasLine() ) );    
       
   915     CleanupStack::PopAndDestroy( oldSessionSdpLines );
       
   916   
       
   917     TInt bandwidthAs = 0;
       
   918     TRAPD( err, bandwidthAs = 
       
   919                 MultimediaSharingSettings::VideoBandwidthSettingL() );
       
   920     __ASSERT_ALWAYS( err == KErrNone || err == KErrNotFound,
       
   921                      User::Leave( err ) );
       
   922     TBool useTias = ( bandwidthAs > 0 );
       
   923 
       
   924     CDesC8Array* newSessionSDPLines = 
       
   925                     new ( ELeave ) CDesC8ArrayFlat( KMusEngArrayGranularity3 );
       
   926     CleanupStack::PushL( newSessionSDPLines );
       
   927     
       
   928     if ( iOperatorVariant )
       
   929         {
       
   930         newSessionSDPLines->AppendL( KMusEngSessionSdpLineApplication() );
       
   931         newSessionSDPLines->AppendL( KMusEngSessionSdpLineType() );
       
   932         }
       
   933     else
       
   934     	{
       
   935     	newSessionSDPLines->AppendL( KMusEngSessionSdpLineXApplication() );    	
       
   936     	}
       
   937         
       
   938     if ( bandwidthAtSessionLevel && ( iOperatorVariant || 
       
   939          ( aForceBandwidthLine && !useTias ) ) )
       
   940         {        
       
   941         MUS_LOG( "mus: [ENGINE] setting bandwidth to session level" )
       
   942         newSessionSDPLines->AppendL( KMusEngSessionSdpLineBandwidthField() );
       
   943         }
       
   944     else if ( !iOperatorVariant && useTias && aForceBandwidthLine &&
       
   945             ( bandwidthAtSessionLevel || tiasAtSessionLevel ) )
       
   946         {
       
   947         MUS_LOG( "mus: [ENGINE] setting b=AS and b=TIAS to session level" )
       
   948         AddSdpBandwidthAttributesL( *newSessionSDPLines, bandwidthAs );
       
   949         }
       
   950    
       
   951     aSession.SetSessionSDPLinesL( newSessionSDPLines );
       
   952     
       
   953     CleanupStack::Pop( newSessionSDPLines );
       
   954     
       
   955     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::SetSessionSdpLinesL()" )
       
   956     }
       
   957 
       
   958 
       
   959 // -----------------------------------------------------------------------------
       
   960 // Setting media level sdp lines. In operator variant mode or when TIAS usage
       
   961 // is disabled bandwidth is not set to media level if it is used already at 
       
   962 // session level. In non operator variant and TIAS enabled case both AS and
       
   963 // TIAS attributes are set to media level if: 1)it is an outcoming sessions
       
   964 // or 2) incoming session had bandwidth attributes on media level or didn't
       
   965 // have bandwidth attributes at all
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 void CMusEngMceSession::SetMediaSdpLinesL( 
       
   969     CMceMediaStream& aStream, 
       
   970     TBool aForceBandwidthLine )
       
   971     {
       
   972     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::SetMediaSdpLinesL()" )
       
   973     
       
   974     MDesC8Array* sessionSdpLines = aStream.Session()->SessionSDPLinesL();
       
   975     CleanupDeletePushL( sessionSdpLines );
       
   976     TBool bandwidthAtSessionLevel( ContainsText( sessionSdpLines, 
       
   977                                    KMusEngSessionSdpLineBandwidthLine() ) );
       
   978 
       
   979     TInt bandwidthAs = 0;
       
   980     TRAPD( error, bandwidthAs = 
       
   981                   MultimediaSharingSettings::VideoBandwidthSettingL() );
       
   982     __ASSERT_ALWAYS( error == KErrNone || error == KErrNotFound,
       
   983                      User::Leave( error ) );
       
   984     TBool useTias = ( bandwidthAs > 0 );
       
   985     TBool tiasOrAsAtSessionLevel = EFalse;
       
   986     TBool tiasOrAsAtMediaLevel = EFalse;
       
   987     if ( useTias )
       
   988         {
       
   989         tiasOrAsAtSessionLevel = IsBandwidthAttributeSet( sessionSdpLines );
       
   990         MDesC8Array* mediaSdpLines = aStream.MediaAttributeLinesL();
       
   991         tiasOrAsAtMediaLevel = IsBandwidthAttributeSet( mediaSdpLines );
       
   992         delete mediaSdpLines;        
       
   993         }
       
   994 
       
   995     CleanupStack::PopAndDestroy( sessionSdpLines );
       
   996 
       
   997     TBool setTiasAtMediaLevel = ( tiasOrAsAtMediaLevel || 
       
   998                                 ( aForceBandwidthLine && 
       
   999                                   !tiasOrAsAtSessionLevel ) );
       
  1000   
       
  1001     const TInt KMusMediaSdpLinesGranularity = 2;
       
  1002     CDesC8Array* headers = 
       
  1003         new ( ELeave ) CDesC8ArrayFlat( KMusMediaSdpLinesGranularity );
       
  1004     CleanupStack::PushL( headers );
       
  1005     
       
  1006     if ( !bandwidthAtSessionLevel && ( iOperatorVariant || 
       
  1007          ( aForceBandwidthLine && !useTias ) ) )
       
  1008         {
       
  1009         MUS_LOG( "mus: [ENGINE] setting bandwidth to media level" )
       
  1010         headers->AppendL( KMusEngSessionSdpLineBandwidthField() );
       
  1011         }
       
  1012     else if ( !iOperatorVariant && useTias && setTiasAtMediaLevel )
       
  1013         {
       
  1014         MUS_LOG( "mus: [ENGINE] setting b=AS and b=TIAS to media level" )
       
  1015         AddSdpBandwidthAttributesL( *headers, bandwidthAs );
       
  1016         }
       
  1017 
       
  1018     aStream.SetMediaAttributeLinesL( headers );   
       
  1019     CleanupStack::Pop( headers );
       
  1020 
       
  1021     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::SetMediaSdpLinesL()" )
       
  1022     }
       
  1023     
       
  1024 // -----------------------------------------------------------------------------
       
  1025 // Changes volume of all speaker sinks in the session structure
       
  1026 // -----------------------------------------------------------------------------
       
  1027 //
       
  1028 void CMusEngMceSession::SetSpeakerVolumeL( TInt aNewVolume )
       
  1029     {
       
  1030     TInt sessionState = iSession->State();
       
  1031 
       
  1032     if ( sessionState != CMceSession::EIdle &&
       
  1033          sessionState != CMceSession::EIncoming )
       
  1034         {
       
  1035         for ( TInt i = 0; i < iSession->Streams().Count(); ++i )
       
  1036             {
       
  1037             CMceSpeakerSink* speaker = 
       
  1038                 MusEngMceUtils::GetSpeaker( *( iSession->Streams()[i] ) );
       
  1039             
       
  1040             if ( speaker &&        
       
  1041                  aNewVolume >= 1 &&
       
  1042                  aNewVolume <= speaker->MaxVolumeL() )
       
  1043                 {
       
  1044                 speaker->SetVolumeL( aNewVolume );
       
  1045                 }
       
  1046 
       
  1047             }
       
  1048         }
       
  1049     }
       
  1050 
       
  1051 // -----------------------------------------------------------------------------
       
  1052 //
       
  1053 // -----------------------------------------------------------------------------
       
  1054 //   
       
  1055 void CMusEngMceSession::AdjustStreamsAndCodecsL()
       
  1056     {
       
  1057     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::AdjustStreamsAndCodecsL" )
       
  1058 
       
  1059     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
  1060 
       
  1061     const RPointerArray<CMceMediaStream>& streams = iSession->Streams();
       
  1062 
       
  1063     for ( TInt i = 0; i < streams.Count(); ++i )
       
  1064         {
       
  1065         if ( streams[i]->Type() == KMceVideo )
       
  1066             {
       
  1067             CMceVideoStream* videoStream =
       
  1068                                     static_cast<CMceVideoStream*>( streams[i] );
       
  1069             
       
  1070             AdjustVideoStreamL( *videoStream );
       
  1071             
       
  1072             if ( videoStream->BoundStream() )
       
  1073                 {
       
  1074                 AdjustVideoStreamL( static_cast<CMceVideoStream&>
       
  1075                                         ( videoStream->BoundStreamL() ) );
       
  1076                 } 
       
  1077             }
       
  1078         else // audio
       
  1079             {
       
  1080             CMceAudioStream* audioStream = 
       
  1081                                     static_cast<CMceAudioStream*>( streams[i] );
       
  1082             
       
  1083             AdjustAudioStreamL( *audioStream );
       
  1084             
       
  1085             if ( audioStream->BoundStream() )
       
  1086                 {
       
  1087                 AdjustAudioStreamL( static_cast<CMceAudioStream&>
       
  1088                                         ( audioStream->BoundStreamL() ) );
       
  1089                 }
       
  1090         
       
  1091             }
       
  1092         }
       
  1093     
       
  1094     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::AdjustStreamsAndCodecsL" )
       
  1095     }
       
  1096 
       
  1097 // -----------------------------------------------------------------------------
       
  1098 //
       
  1099 // -----------------------------------------------------------------------------
       
  1100 //  
       
  1101 void CMusEngMceSession::AdjustVideoStreamL( CMceVideoStream& aVideoStream )
       
  1102     {
       
  1103     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::AdjustVideoStreamL" )
       
  1104     
       
  1105     aVideoStream.SetLocalMediaPortL( KMusEngDedicatedVideoPort );
       
  1106     
       
  1107     DoCodecSelectionL( aVideoStream );
       
  1108     
       
  1109     const RPointerArray<CMceVideoCodec>& codecs = aVideoStream.Codecs();
       
  1110     
       
  1111     __ASSERT_ALWAYS( aVideoStream.Source(), User::Leave( KErrArgument ) );
       
  1112     for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex )
       
  1113         {
       
  1114         AdjustVideoCodecL( *codecs[codecIndex], aVideoStream.Source()->Type() );
       
  1115         }
       
  1116     
       
  1117     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::AdjustVideoStreamL" )
       
  1118     }
       
  1119 
       
  1120 // -----------------------------------------------------------------------------
       
  1121 //
       
  1122 // -----------------------------------------------------------------------------
       
  1123 //  
       
  1124 void CMusEngMceSession::AdjustAudioStreamL( CMceAudioStream& aAudioStream )
       
  1125     {
       
  1126     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::AdjustAudioStreamL" )
       
  1127     
       
  1128     aAudioStream.SetLocalMediaPortL( KMusEngDedicatedAudioPort );
       
  1129 
       
  1130     const RPointerArray<CMceAudioCodec> codecs = aAudioStream.Codecs();
       
  1131     
       
  1132     for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex )
       
  1133         {
       
  1134         AdjustAudioCodecL( *codecs[codecIndex] );
       
  1135         }
       
  1136     
       
  1137     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::AdjustAudioStreamL" )
       
  1138     }
       
  1139 
       
  1140 // -----------------------------------------------------------------------------
       
  1141 // Calls CMceInSession::RejectL() inside TRAP_IGNORE
       
  1142 // -----------------------------------------------------------------------------
       
  1143 //
       
  1144 void CMusEngMceSession::Reject( CMceInSession& aSession,
       
  1145                                 const TDesC8& aReason,
       
  1146                                 TUint32 aCode )
       
  1147     {
       
  1148     if ( aCode != 0 || aReason != KNullDesC8() )
       
  1149         {
       
  1150         TRAP_IGNORE( aSession.RejectL( aReason, aCode, NULL, NULL, NULL ) )
       
  1151         }
       
  1152     else
       
  1153         {
       
  1154         if ( iOperatorVariant )
       
  1155             {
       
  1156             // In operator variant, session is rejected with 486 instead of 603.
       
  1157             // Also the reason phrase is supposed to be "Busy".
       
  1158             TRAP_IGNORE( aSession.RejectL( KMusEngSipReasonPhraseBusy(), 
       
  1159                                            KMusEngSipReasonCodeBusyHere ) )
       
  1160             }
       
  1161         else
       
  1162             {
       
  1163             // Normal case
       
  1164             TRAP_IGNORE( aSession.RejectL() )
       
  1165             }
       
  1166         }
       
  1167     }  
       
  1168 
       
  1169 // -----------------------------------------------------------------------------
       
  1170 // By default rejects all incoming sessions immediately without notifying UI
       
  1171 // -----------------------------------------------------------------------------
       
  1172 //
       
  1173 void CMusEngMceSession::IncomingSession( 
       
  1174     CMceInSession* aSession,
       
  1175     TMceTransactionDataContainer* /*aContainer*/ )
       
  1176     {
       
  1177     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::IncomingSession()" )
       
  1178     
       
  1179     Reject( *aSession, 
       
  1180             KMusEngSipReasonPhraseBusyHere(),
       
  1181             KMusEngSipReasonCodeBusyHere );
       
  1182              
       
  1183     delete aSession;
       
  1184     aSession = NULL;    
       
  1185     
       
  1186     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::IncomingSession()" )
       
  1187     }
       
  1188 
       
  1189 // -----------------------------------------------------------------------------
       
  1190 // By default rejects all incoming updates immediately without notifying UI
       
  1191 // -----------------------------------------------------------------------------
       
  1192 //
       
  1193 void CMusEngMceSession::IncomingUpdate( 
       
  1194     CMceSession& aOrigSession, 
       
  1195     CMceInSession* aUpdatedSession,
       
  1196     TMceTransactionDataContainer* /*aContainer*/ )
       
  1197     {
       
  1198     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::IncomingUpdate()" )
       
  1199                                     
       
  1200     if ( iSession &&
       
  1201          iSession == &aOrigSession )
       
  1202         {
       
  1203         // Old session is useless from now on
       
  1204         delete iSession;
       
  1205         iSession = aUpdatedSession;
       
  1206         MUS_LOG( "mus: [ENGINE]  Unexpected update, reject" )
       
  1207         Reject( *aUpdatedSession );    
       
  1208         }
       
  1209     else
       
  1210         {
       
  1211         // This should never happen
       
  1212         MUS_LOG( "mus: [ENGINE]  Unknown update, reject and delete" )
       
  1213         Reject( *aUpdatedSession );    
       
  1214         delete aUpdatedSession;
       
  1215         } 
       
  1216     
       
  1217     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::IncomingUpdate()" )    
       
  1218     }  
       
  1219 
       
  1220 // -----------------------------------------------------------------------------
       
  1221 //
       
  1222 // -----------------------------------------------------------------------------
       
  1223 //
       
  1224 void CMusEngMceSession::StreamStateChanged( CMceMediaStream& aStream )
       
  1225     {
       
  1226     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::StreamStateChanged()" )
       
  1227     
       
  1228     if ( !iSession )
       
  1229         {
       
  1230         return; // We cannot do anything
       
  1231         }
       
  1232     
       
  1233     MUS_ENG_LOG_STREAM_STATE( aStream )
       
  1234         
       
  1235     switch ( aStream.State() )
       
  1236         {
       
  1237         case CMceMediaStream::EUninitialized: // Stream is created
       
  1238             {
       
  1239             // Unexpected state change
       
  1240             break;
       
  1241             }
       
  1242         case CMceMediaStream::EInitialized: // Stream is initialized
       
  1243             {
       
  1244             // Should be handled in sibling classes if needed
       
  1245             break;
       
  1246             }
       
  1247         case CMceMediaStream::EBuffering: // Stream is buffering
       
  1248             {
       
  1249             // Should be handled in sibling classes if needed
       
  1250             break;
       
  1251             }
       
  1252         case CMceMediaStream::EIdle: // Stream is not receiving RTP
       
  1253             {
       
  1254             // NOP
       
  1255             break;
       
  1256             }
       
  1257         case CMceMediaStream::EStreaming: // Stream is streaming
       
  1258             {
       
  1259             StreamStreaming( aStream );
       
  1260             break;
       
  1261             }
       
  1262         case CMceMediaStream::EDisabled: // Stream is explicitly disabled
       
  1263             {
       
  1264             break;
       
  1265             }
       
  1266         case CMceMediaStream::ENoResources: 
       
  1267             {
       
  1268             // Stream has no needed resources to stream
       
  1269             break;
       
  1270             }         
       
  1271         case CMceMediaStream::ETranscodingRequired: 
       
  1272             {
       
  1273             // Stream requires non-realtime transcoding
       
  1274             // Should be handled in sibling classes
       
  1275             break;
       
  1276             }   
       
  1277         case CMceMediaStream::ETranscoding: 
       
  1278             {
       
  1279             // Stream is transcoding in non-realtime
       
  1280             // Should be handled in sibling classes
       
  1281             break;
       
  1282             }       
       
  1283         default:
       
  1284             {
       
  1285             break;
       
  1286             }
       
  1287         }
       
  1288     
       
  1289     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::StreamStateChanged()" )
       
  1290                 
       
  1291     }
       
  1292 
       
  1293 // -----------------------------------------------------------------------------
       
  1294 //
       
  1295 // -----------------------------------------------------------------------------
       
  1296 //
       
  1297 void CMusEngMceSession::StreamStateChanged( CMceMediaStream& aStream,
       
  1298                                             CMceMediaSource& /*aSource*/ )
       
  1299     {
       
  1300     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::StreamStateChanged( src )" )
       
  1301     // Use default logic
       
  1302     StreamStateChanged( aStream );
       
  1303     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::StreamStateChanged( src )" )       
       
  1304     }
       
  1305 
       
  1306 // -----------------------------------------------------------------------------
       
  1307 //
       
  1308 // -----------------------------------------------------------------------------
       
  1309 //
       
  1310 void CMusEngMceSession::StreamStateChanged( CMceMediaStream& aStream,
       
  1311                                             CMceMediaSink& /*aSink*/ )
       
  1312     {
       
  1313     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::StreamStateChanged( sink )" )
       
  1314     // Use default logic
       
  1315     StreamStateChanged( aStream );
       
  1316     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::StreamStateChanged( sink )" )
       
  1317     }
       
  1318 
       
  1319 // -----------------------------------------------------------------------------
       
  1320 //
       
  1321 // -----------------------------------------------------------------------------
       
  1322 //
       
  1323 void CMusEngMceSession::SessionStateChanged(
       
  1324     CMceSession& aSession,
       
  1325     TMceTransactionDataContainer* aContainer )
       
  1326     {
       
  1327     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::SessionStateChanged()" )
       
  1328         
       
  1329     if ( !aContainer )
       
  1330         {
       
  1331         // Container should never be NULL, but if it is, handle as
       
  1332         // internal error
       
  1333         InformObserverAboutSessionFailure( KErrGeneral );
       
  1334         return;
       
  1335         }
       
  1336 
       
  1337     // This is the only point to get statuscode and reasonphrase. With this call
       
  1338     // they are zeroed and thus cannot be got anymore.
       
  1339     TInt statusCode = aContainer->GetStatusCode();
       
  1340     HBufC8* reasonPhrase = aContainer->GetReasonPhrase();
       
  1341     
       
  1342     if ( reasonPhrase )
       
  1343         {        
       
  1344         HandleSessionStateChanged( aSession, statusCode, *reasonPhrase ); 
       
  1345         delete reasonPhrase ;       
       
  1346         }
       
  1347     else
       
  1348         {
       
  1349         HandleSessionStateChanged( aSession, statusCode, KNullDesC8() );
       
  1350         }
       
  1351     
       
  1352     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::SessionStateChanged()" )
       
  1353     }     
       
  1354     
       
  1355 // -----------------------------------------------------------------------------
       
  1356 //
       
  1357 // -----------------------------------------------------------------------------
       
  1358 //
       
  1359 void CMusEngMceSession::SessionConnectionStateChanged( CMceSession& aSession,
       
  1360                                                        TBool aActive )
       
  1361     {
       
  1362     MUS_LOG1( "mus: [ENGINE]     CMusEngMceSession::\
       
  1363               SessionConnectionStateChanged() active = %b", aActive )
       
  1364 
       
  1365     if ( iSession && iSession == &aSession )
       
  1366         {
       
  1367         if ( !aActive )
       
  1368             {
       
  1369             MUS_LOG( "mus: [ENGINE]     CMusEngMceSession::\
       
  1370                      SessionConnectionStateChanged: Notify observer" )
       
  1371             InformObserverAboutSessionFailure( MLcSession::EConnectionLost );
       
  1372             }
       
  1373         }
       
  1374 
       
  1375     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::\
       
  1376              SessionConnectionStateChanged()" )
       
  1377     }
       
  1378 
       
  1379 // -----------------------------------------------------------------------------
       
  1380 //
       
  1381 // -----------------------------------------------------------------------------
       
  1382 //
       
  1383 void CMusEngMceSession::Failed( CMceSession& aSession, TInt aError )
       
  1384     {
       
  1385     MUS_LOG1( "mus: [ENGINE]     -> CMusEngMceSession::Failed() error #%d", 
       
  1386               aError )
       
  1387     
       
  1388     if ( iSession && iSession == &aSession )
       
  1389         {
       
  1390         MUS_LOG( "mus: [ENGINE]    CMusEngMceSession::Failed: Notify observer" )
       
  1391         InformObserverAboutSessionFailure( aError );
       
  1392         }
       
  1393 
       
  1394     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::Failed()" )
       
  1395     }
       
  1396 
       
  1397 // -----------------------------------------------------------------------------
       
  1398 //
       
  1399 // -----------------------------------------------------------------------------
       
  1400 //
       
  1401 void CMusEngMceSession::UpdateFailed(
       
  1402     CMceSession& aSession,
       
  1403     TMceTransactionDataContainer* aContainer )
       
  1404     {
       
  1405     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::UpdateFailed()" )
       
  1406 
       
  1407     if ( !aContainer )
       
  1408         {
       
  1409         // Container should never be NULL, but if it is, handle as
       
  1410         // internal error
       
  1411         InformObserverAboutSessionFailure( KErrGeneral );
       
  1412         return;
       
  1413         }
       
  1414 
       
  1415     if ( iSession && iSession == &aSession )
       
  1416         {
       
  1417         MUS_LOG( "mus: [ENGINE]     CMusEngMceSession::UpdateFailed: \
       
  1418                  Notify observer" )
       
  1419         InformObserverAboutSessionFailure( KErrGeneral );
       
  1420         }
       
  1421 
       
  1422     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::UpdateFailed()" )
       
  1423     }
       
  1424 
       
  1425 // -----------------------------------------------------------------------------
       
  1426 //
       
  1427 // -----------------------------------------------------------------------------
       
  1428 //
       
  1429 void CMusEngMceSession::SRReceived( CMceSession& aSession,
       
  1430 					                CMceMediaStream& aStream)
       
  1431     {
       
  1432     // No logging because of amount of reports
       
  1433     if ( iSession &&
       
  1434          iSession == &aSession )
       
  1435         {
       
  1436         for ( TInt i = 0; i < iSession->Streams().Count(); ++i )
       
  1437             {
       
  1438             if ( &aStream == iSession->Streams()[i] )
       
  1439                 {
       
  1440                 iSecondsFromLastRtcpReport = 0;
       
  1441                 }
       
  1442             }
       
  1443         }
       
  1444     }
       
  1445 
       
  1446 // -----------------------------------------------------------------------------
       
  1447 //
       
  1448 // -----------------------------------------------------------------------------
       
  1449 //
       
  1450 void CMusEngMceSession::RRReceived( CMceSession& aSession,
       
  1451 					                CMceMediaStream& aStream)
       
  1452     {
       
  1453     // No logging because of amount of reports
       
  1454 
       
  1455     if ( iSession &&
       
  1456          iSession == &aSession )
       
  1457         {
       
  1458         for ( TInt i = 0; i < iSession->Streams().Count(); ++i )
       
  1459             {
       
  1460             if ( &aStream == iSession->Streams()[i] )
       
  1461                 {
       
  1462                 iSecondsFromLastRtcpReport = 0;
       
  1463                 }
       
  1464             }
       
  1465         }
       
  1466     }					             
       
  1467 
       
  1468 // -----------------------------------------------------------------------------
       
  1469 //
       
  1470 // -----------------------------------------------------------------------------
       
  1471 //
       
  1472 void CMusEngMceSession::InactivityTimeout( CMceMediaStream& aStream,
       
  1473                                            CMceRtpSource& /*aSource*/ )
       
  1474     {
       
  1475     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::InactivityTimeout()" )
       
  1476     // This function may be deprecated in future and after that similar 
       
  1477     // functionality can be obtained by observing stream state EIdle.
       
  1478     // Anyway it does not work yet and until then, informing UI about 
       
  1479     // RTP inactivity is done in this function.
       
  1480     
       
  1481     if ( aStream.Type() == KMceVideo )
       
  1482         {
       
  1483         InformObserverAboutPlayerStateChange( RemoteVideoPlayer() );
       
  1484         }
       
  1485     
       
  1486     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::InactivityTimeout()" )
       
  1487     }
       
  1488 
       
  1489 // -----------------------------------------------------------------------------
       
  1490 //
       
  1491 // -----------------------------------------------------------------------------
       
  1492 //
       
  1493 void CMusEngMceSession::SsrcAdded( CMceMediaStream& /*aStream*/,
       
  1494                                    CMceRtpSource& /*aSource*/,
       
  1495                                    TUint /*aSsrc*/ )
       
  1496     {
       
  1497     MUS_LOG( "mus: [ENGINE]  CMusEngMceSession::SsrcAdded( ... )" )
       
  1498     // NOP, We are not at all interested about SSRCs
       
  1499     }
       
  1500 
       
  1501 // -----------------------------------------------------------------------------
       
  1502 //
       
  1503 // -----------------------------------------------------------------------------
       
  1504 //
       
  1505 void CMusEngMceSession::SsrcRemoved( CMceMediaStream& /*aStream*/,
       
  1506                                      CMceRtpSource& /*aSource*/,
       
  1507                                      TUint /*aSsrc*/ )
       
  1508     {
       
  1509     MUS_LOG( "mus: [ENGINE]  CMusEngMceSession::SsrcRemoved(... )" )
       
  1510     // NOP, We are not at all interested about SSRCs
       
  1511     }
       
  1512 
       
  1513 // -----------------------------------------------------------------------------
       
  1514 //
       
  1515 // -----------------------------------------------------------------------------
       
  1516 //
       
  1517 TBool CMusEngMceSession::IsRoamingBetweenAPsAllowed()
       
  1518     {
       
  1519     TBool allowed( ETrue );
       
  1520     if ( iSession && 
       
  1521          iSession->State() != CMceSession::EIdle &&
       
  1522          iSession->State() != CMceSession::ETerminated )
       
  1523         {
       
  1524         allowed = EFalse;
       
  1525         }
       
  1526     return allowed;
       
  1527     }
       
  1528 
       
  1529 // -----------------------------------------------------------------------------
       
  1530 //
       
  1531 // -----------------------------------------------------------------------------
       
  1532 //
       
  1533 void CMusEngMceSession::ProfileRegistered()
       
  1534     {
       
  1535     // NOP in base class
       
  1536     }
       
  1537 
       
  1538 // -----------------------------------------------------------------------------
       
  1539 //
       
  1540 // -----------------------------------------------------------------------------
       
  1541 //
       
  1542 void CMusEngMceSession::HandleSessionStateChanged( CMceSession& aSession,
       
  1543                                                    TInt aStatusCode,
       
  1544                                                    const TDesC8& aReasonPhrase )
       
  1545     {
       
  1546     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::HandleSessionStateChanged" )
       
  1547     
       
  1548     MUS_ENG_LOG_SESSION_STATE_AND_STATUS( aSession, aStatusCode, aReasonPhrase ) 
       
  1549 
       
  1550     if ( iSession && iSession == &aSession )
       
  1551         {
       
  1552         switch ( aSession.State() )
       
  1553             {
       
  1554             case CMceSession::EIdle:
       
  1555             case CMceSession::EIncoming:
       
  1556                 {
       
  1557                 MUS_LOG( "mus: [ENGINE] Unexpected asynchronous \
       
  1558                          state transition, consider session as failed." )
       
  1559                 InformObserverAboutSessionFailure( KErrGeneral );
       
  1560                 break;
       
  1561                 }
       
  1562             case CMceSession::EEstablished:
       
  1563                 {
       
  1564                 if ( iStoreEncoderConfigInfo )
       
  1565                     {
       
  1566                     iStoreEncoderConfigInfo = EFalse;
       
  1567                     TRAPD( error, StoreEncoderConfigInfoL() )
       
  1568                     if ( error != KErrNone && error != KErrNotFound )
       
  1569                         {
       
  1570                         // Only acceptable error is absence of repository entry,
       
  1571                         // otherwise we inform user about failed session.
       
  1572                         InformObserverAboutSessionFailure( error );
       
  1573                         return;
       
  1574                         }
       
  1575                     }
       
  1576                 
       
  1577                 // Check that session timer is not already running, which is 
       
  1578                 // the case when refreshing the session with session timer 
       
  1579                 if ( !iUpdateTimer->IsActive() )
       
  1580                     {
       
  1581                     iStartTime.HomeTime(); // Start counting session duration              
       
  1582                     iUpdateTimer->Start( KMusEngTimerInterval );
       
  1583                     InformObserverAboutSessionStateChange();
       
  1584                     }
       
  1585                 
       
  1586                 break;
       
  1587                 }
       
  1588             case CMceSession::EOffering:
       
  1589             case CMceSession::EReserving:
       
  1590             case CMceSession::EAnswering:
       
  1591             case CMceSession::EProceeding:              
       
  1592             case CMceSession::ECancelling:
       
  1593             case CMceSession::ETerminating:
       
  1594                 {
       
  1595                 // NOP
       
  1596                 break;
       
  1597                 }
       
  1598             case CMceSession::ETerminated:
       
  1599                 {
       
  1600                 HandleTermination( aStatusCode, aReasonPhrase );
       
  1601                 break;
       
  1602                 }
       
  1603             default:
       
  1604                 {
       
  1605                 MUS_LOG( "mus: [ENGINE]  CMusEngMceSession::SessionStateChanged(), \
       
  1606                          default case" )
       
  1607                 break;
       
  1608                 }
       
  1609             }
       
  1610         }
       
  1611         
       
  1612     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::HandleSessionStateChanged" )
       
  1613     }
       
  1614 
       
  1615 // -----------------------------------------------------------------------------
       
  1616 // This function should be called only if sibling classes cannot handle
       
  1617 // termination reason by themselves.
       
  1618 // -----------------------------------------------------------------------------
       
  1619 //
       
  1620 void CMusEngMceSession::HandleTermination( TInt aStatusCode,
       
  1621                                            const TDesC8& /*aReasonPhrase*/ )
       
  1622     {
       
  1623     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::HandleTermination()" )
       
  1624 
       
  1625     iSipProfileHandler->RefreshIapAvailabilities();
       
  1626     
       
  1627     switch ( aStatusCode )
       
  1628         {
       
  1629         case 0:
       
  1630             {
       
  1631             // Normal session termination or session by another end.
       
  1632             InformObserverAboutSessionStateChange();
       
  1633             break;
       
  1634             }
       
  1635         case KMusEngSipReasonCodeOk:
       
  1636             {
       
  1637             // Normal session termination by this end: We have sent BYE
       
  1638             // and now received 200 OK to it.
       
  1639             InformObserverAboutSessionStateChange();
       
  1640             break;
       
  1641             }
       
  1642         default:
       
  1643             {
       
  1644             // Termination reason cannot be determined, handle as internal
       
  1645             // error.
       
  1646             InformObserverAboutSessionFailure( KErrGeneral );
       
  1647             break;
       
  1648             }
       
  1649         }
       
  1650 
       
  1651     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::HandleTermination()" )
       
  1652     }
       
  1653 
       
  1654 // -----------------------------------------------------------------------------
       
  1655 //
       
  1656 // -----------------------------------------------------------------------------
       
  1657 //
       
  1658 void CMusEngMceSession::AdjustVideoCodecL( CMceVideoCodec& aVideoCodec,
       
  1659                                            TMceSourceType aSourceType )
       
  1660     {
       
  1661     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::AdjustVideoCodecL()" )
       
  1662     
       
  1663     aVideoCodec.SetMMFPriorityL( KAudioPrioritySwisPlayback );
       
  1664     aVideoCodec.SetMMFPriorityPreferenceL( KAudioPrefSwisPlayback );
       
  1665 
       
  1666     if ( aVideoCodec.SdpName() == KMceSDPNameH264() &&
       
  1667          aSourceType == KMceCameraSource )
       
  1668         {
       
  1669         SetCodecConfigKeyL( aVideoCodec );
       
  1670         SetEncodingDeviceL( aVideoCodec );     
       
  1671         }
       
  1672     
       
  1673     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::AdjustVideoCodecL()" )
       
  1674     }
       
  1675  
       
  1676 // -----------------------------------------------------------------------------
       
  1677 // 1. Sets MMF audio priority and preference
       
  1678 // -----------------------------------------------------------------------------
       
  1679 //
       
  1680 void CMusEngMceSession::AdjustAudioCodecL( CMceAudioCodec& aAudioCodec )
       
  1681     {
       
  1682     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::AdjustAudioCodecL()" )
       
  1683     
       
  1684     aAudioCodec.SetMMFPriorityL( KAudioPrioritySwisPlayback );
       
  1685     aAudioCodec.SetMMFPriorityPreferenceL( KAudioPrefSwisPlayback );
       
  1686     MUS_LOG( "mus: [ENGINE]     Audio MMF priority and preference set" )
       
  1687     
       
  1688     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::AdjustAudioCodecL()" )
       
  1689     }
       
  1690 
       
  1691 // -----------------------------------------------------------------------------
       
  1692 // Remove multiples of H.263 codec, prefer H263-2000 over H263-1998.
       
  1693 // Additionally select just the one with best quality from selected mode.
       
  1694 // -----------------------------------------------------------------------------
       
  1695 //
       
  1696 void CMusEngMceSession::DoCodecSelectionL( CMceVideoStream& aVideoStream )
       
  1697     {
       
  1698     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::DoCodecSelectionL()" )
       
  1699     
       
  1700     const RPointerArray<CMceVideoCodec>& codecs = aVideoStream.Codecs();
       
  1701     TBool codecModeBasedRemovalNeeded( EFalse );
       
  1702     // Label:H263
       
  1703     TBool H2632000CodecFound( EFalse );
       
  1704     TBool H2631998CodecFound( EFalse );
       
  1705     for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex )
       
  1706         {
       
  1707         const CMceVideoCodec& currentCodec = *codecs[codecIndex];
       
  1708         if ( currentCodec.SdpName().FindF( KMceSDPNameH263 ) != KErrNotFound )
       
  1709             { 
       
  1710             if ( !currentCodec.SdpName().CompareF( KMceSDPNameH2632000 ) )
       
  1711                 {
       
  1712                 H2632000CodecFound = ETrue;
       
  1713                 codecModeBasedRemovalNeeded = H2631998CodecFound;
       
  1714                 }  
       
  1715             else if ( !currentCodec.SdpName().CompareF( KMceSDPNameH2631998 ) )
       
  1716                 {
       
  1717                 H2631998CodecFound = ETrue;
       
  1718                 codecModeBasedRemovalNeeded = H2632000CodecFound;
       
  1719                 }
       
  1720             else 
       
  1721                 {
       
  1722                 // NOP
       
  1723                 }
       
  1724             }
       
  1725         }
       
  1726     if ( codecModeBasedRemovalNeeded )
       
  1727         {
       
  1728         DoCodecModeBasedRemovalL( aVideoStream );
       
  1729         }
       
  1730     
       
  1731     const RPointerArray<CMceVideoCodec>& codecs2 = aVideoStream.Codecs();
       
  1732     const CMceVideoCodec* bestBitrateCodec( NULL );
       
  1733     for ( TInt codecIndex = 0; codecIndex < codecs2.Count(); ++codecIndex )
       
  1734         {
       
  1735         const CMceVideoCodec& currentCodec = *codecs2[codecIndex];
       
  1736         if ( currentCodec.SdpName().FindF( KMceSDPNameH263 ) != KErrNotFound )
       
  1737             {
       
  1738             if ( !bestBitrateCodec || 
       
  1739                  currentCodec.MaxBitRate() > bestBitrateCodec->MaxBitRate() )
       
  1740                 {
       
  1741                 bestBitrateCodec = &currentCodec;
       
  1742                 } 
       
  1743             }
       
  1744         }        
       
  1745     if ( bestBitrateCodec )
       
  1746         {
       
  1747         DoBitrateBasedRemovalL( aVideoStream, *bestBitrateCodec );
       
  1748         }
       
  1749    
       
  1750     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::DoCodecSelectionL()" )
       
  1751     }
       
  1752     
       
  1753 // -----------------------------------------------------------------------------
       
  1754 //
       
  1755 // -----------------------------------------------------------------------------
       
  1756 //
       
  1757 void CMusEngMceSession::UpdateTimerEvent()
       
  1758     {
       
  1759     // Update timer is used also to detect RTCP inactivity
       
  1760     ++iSecondsFromLastRtcpReport;
       
  1761 
       
  1762     if ( iSecondsFromLastRtcpReport >= KMusEngRtcpInactivityThreshold )
       
  1763         {
       
  1764         MUS_LOG( "mus: [ENGINE] CMusEngMceSession::UpdateTimerEvent() ->EMediaInactivityTimeout" )
       
  1765         InformObserverAboutSessionFailure( MLcSession::EMediaInactivityTimeout );
       
  1766         // Disable calling multiple times by reseting timer
       
  1767         iSecondsFromLastRtcpReport = 0;
       
  1768         }
       
  1769 
       
  1770     iUpdateTimer->Start( KMusEngTimerInterval );
       
  1771     }
       
  1772 
       
  1773 // -----------------------------------------------------------------------------
       
  1774 // Enables or disables all the speaker sinks of all the audio streams
       
  1775 // -----------------------------------------------------------------------------
       
  1776 //
       
  1777 void CMusEngMceSession::DoMuteSpeakerL( TBool aMute )
       
  1778     {
       
  1779     MUS_LOG1( "mus: [ENGINE]     -> CMusEngMceSession::MuteL( %d )", aMute )
       
  1780     
       
  1781     const RPointerArray<CMceMediaStream>& streams = iSession->Streams();
       
  1782 
       
  1783     for ( TInt i = 0; i < streams.Count(); ++i )
       
  1784         {
       
  1785         CMceSpeakerSink* speaker = MusEngMceUtils::GetSpeaker( *streams[i] );
       
  1786             
       
  1787         if ( speaker )
       
  1788             {
       
  1789             if( aMute )
       
  1790                 {
       
  1791                 if ( speaker->IsEnabled() )
       
  1792                     {
       
  1793                     speaker->DisableL();
       
  1794                     }
       
  1795                 else
       
  1796                     {
       
  1797                     MUS_LOG( "mus: [ENGINE]     Speaker already muted, NOP" )
       
  1798                     }
       
  1799                 }
       
  1800             else
       
  1801                 {
       
  1802                 if ( !speaker->IsEnabled() )
       
  1803                     {
       
  1804                     speaker->EnableL();
       
  1805                     }
       
  1806                 else
       
  1807                     {
       
  1808                     MUS_LOG( "mus: [ENGINE]     Speaker already unmuted, NOP" )
       
  1809                     }
       
  1810                 }
       
  1811             }
       
  1812         }
       
  1813         
       
  1814     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::MuteL( TBool aMute )" )
       
  1815     }
       
  1816 
       
  1817 // -----------------------------------------------------------------------------
       
  1818 // Checks if some of array items contains specific text 
       
  1819 // (exact match not required)
       
  1820 // -----------------------------------------------------------------------------
       
  1821 //
       
  1822 TBool CMusEngMceSession::ContainsText( MDesC8Array* aArray, const TDesC8& aItem )
       
  1823     {
       
  1824     for ( TInt i = 0; aArray && i < aArray->MdcaCount(); i++ )
       
  1825         {
       
  1826         if ( aArray->MdcaPoint( i ).FindF( aItem ) != KErrNotFound )
       
  1827             {
       
  1828             return ETrue;
       
  1829             }
       
  1830         }
       
  1831     return EFalse;
       
  1832     }
       
  1833 
       
  1834 // -----------------------------------------------------------------------------
       
  1835 // 
       
  1836 // -----------------------------------------------------------------------------
       
  1837 //
       
  1838 void CMusEngMceSession::DoBitrateBasedRemovalL( 
       
  1839     CMceVideoStream& aVideoStream, 
       
  1840     const CMceVideoCodec& aBestBitrateVideoCodec )
       
  1841     {   
       
  1842     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::DoBitrateBasedRemovalL()" )
       
  1843     
       
  1844     RPointerArray<CMceVideoCodec>& codecs = 
       
  1845         MUS_CODEC_ARR_CONST_CAST( aVideoStream.Codecs() );
       
  1846                           
       
  1847     TInt codecIndex = 0;
       
  1848     while ( codecIndex < codecs.Count() )
       
  1849         {
       
  1850         CMceVideoCodec& currentCodec = *codecs[codecIndex++];
       
  1851         if ( currentCodec.SdpName().FindF( KMceSDPNameH263 ) != KErrNotFound &&
       
  1852              &currentCodec != &aBestBitrateVideoCodec )
       
  1853             {
       
  1854             MUS_LOG( "mus: [ENGINE]         removing" )
       
  1855             aVideoStream.RemoveCodecL( currentCodec );
       
  1856             codecs = MUS_CODEC_ARR_CONST_CAST( aVideoStream.Codecs() );
       
  1857             codecIndex = 0;
       
  1858             }
       
  1859         }
       
  1860         
       
  1861     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::DoBitrateBasedRemovalL()" )
       
  1862     }
       
  1863     
       
  1864 // -----------------------------------------------------------------------------
       
  1865 // 
       
  1866 // -----------------------------------------------------------------------------
       
  1867 //
       
  1868 void CMusEngMceSession::DoCodecModeBasedRemovalL( CMceVideoStream& aVideoStream )
       
  1869     {
       
  1870     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::DoCodecModeBasedRemovalL()" )
       
  1871     
       
  1872     RPointerArray<CMceVideoCodec>& codecs = 
       
  1873         MUS_CODEC_ARR_CONST_CAST( aVideoStream.Codecs() );
       
  1874         
       
  1875     TInt codecIndex = 0;
       
  1876     while ( codecIndex < codecs.Count() )
       
  1877         {
       
  1878         CMceVideoCodec& currentCodec = *codecs[codecIndex++];
       
  1879         if ( !currentCodec.SdpName().CompareF( KMceSDPNameH2631998 ) )
       
  1880             {
       
  1881             MUS_LOG( "mus: [ENGINE]         removing" )
       
  1882             aVideoStream.RemoveCodecL( currentCodec );
       
  1883             codecs = MUS_CODEC_ARR_CONST_CAST( aVideoStream.Codecs() );
       
  1884             codecIndex = 0;
       
  1885             }
       
  1886         }
       
  1887         
       
  1888     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::DoCodecModeBasedRemovalL()" )
       
  1889     }
       
  1890 
       
  1891 // -----------------------------------------------------------------------------
       
  1892 //
       
  1893 // -----------------------------------------------------------------------------
       
  1894 //
       
  1895 void CMusEngMceSession::SetEncodingDeviceL( CMceVideoCodec& aVideoCodec )
       
  1896     {
       
  1897     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::SetEncodingDeviceL()" )
       
  1898 
       
  1899     // We try to read encoding device UID. If we do not succeed, we use default
       
  1900     
       
  1901     const TUid KDefaultEncodingDevice( TUid::Uid( 0x20001C13 ) );
       
  1902     TUid encodingDevice( KDefaultEncodingDevice );
       
  1903     TRAPD( error, 
       
  1904            encodingDevice = MultimediaSharingSettings::EncodingDeviceL() )
       
  1905     __ASSERT_ALWAYS( error == KErrNone || error == KErrNotFound, 
       
  1906                      User::Leave( error ) );
       
  1907     aVideoCodec.SetPreferredEncodingDecodingDeviceL( encodingDevice );
       
  1908     
       
  1909     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::SetEncodingDeviceL()" )
       
  1910     }
       
  1911 
       
  1912 // -----------------------------------------------------------------------------
       
  1913 //
       
  1914 // -----------------------------------------------------------------------------
       
  1915 //
       
  1916 void CMusEngMceSession::SetCodecConfigKeyL( CMceVideoCodec& aVideoCodec )
       
  1917     {
       
  1918     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::SetCodecConfigKeyL()" )
       
  1919     
       
  1920     HBufC8* configKey( NULL );
       
  1921         
       
  1922     // We try to read config key. If we do not succeed, we prepare to
       
  1923     // write keys to CenRep for the next time.
       
  1924     TRAPD( error, configKey = ReadCodecConfigKeyL( aVideoCodec ) )
       
  1925     
       
  1926     if ( error == KErrNone )
       
  1927         {
       
  1928         // There is a repository for config keys
       
  1929         if ( configKey )
       
  1930             {
       
  1931             // ...and key is found.
       
  1932             CleanupStack::PushL( configKey );
       
  1933             aVideoCodec.SetConfigKeyL( *configKey );
       
  1934             CleanupStack::PopAndDestroy( configKey );
       
  1935             }
       
  1936         else
       
  1937             {
       
  1938             // ...but key is not found, so it must be written to CenRep when
       
  1939             // available. 
       
  1940             iStoreEncoderConfigInfo = ETrue;
       
  1941             }
       
  1942         }
       
  1943     else if ( error == KErrNotFound )
       
  1944         {
       
  1945         // There is no repository for config keys so there is no point
       
  1946         // trying to write anything there. Session setup can still continue.
       
  1947         MUS_LOG1( "mus: [ENGINE]    No repository for config keys [%d]", error )
       
  1948         }            
       
  1949     else
       
  1950         {
       
  1951         User::Leave( error );
       
  1952         }
       
  1953     
       
  1954     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::SetCodecConfigKeyL()" )
       
  1955     }
       
  1956 
       
  1957 // -----------------------------------------------------------------------------
       
  1958 //
       
  1959 // -----------------------------------------------------------------------------
       
  1960 //
       
  1961 HBufC8* CMusEngMceSession::ReadCodecConfigKeyL( 
       
  1962     const CMceVideoCodec& aVideoCodec ) const
       
  1963     {
       
  1964     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::ReadCodecConfigKeyL()" )
       
  1965     
       
  1966     HBufC8* key( NULL );
       
  1967  
       
  1968     HBufC8* encoderInfo = MultimediaSharingSettings::EncoderConfigInfoLC();
       
  1969     __ASSERT_ALWAYS( encoderInfo, User::Leave( KErrNotFound ) );
       
  1970     
       
  1971     TPtrC8 keyId( ConfigKeyIdL( aVideoCodec ) ); 
       
  1972     
       
  1973     TInt tokenStartPosition( encoderInfo->FindC( keyId ) );
       
  1974     if ( tokenStartPosition > KErrNotFound )
       
  1975         {
       
  1976         TInt tokenLength( encoderInfo->Mid( tokenStartPosition ).FindC( 
       
  1977                                                 KMusEncoderInfoTokenizer ) );
       
  1978         if ( tokenLength > KErrNotFound )
       
  1979             {
       
  1980             // Separate key from token by removing keyId
       
  1981             TInt keyStartPosition = tokenStartPosition + keyId.Length();
       
  1982             TInt keyLength = tokenLength - keyId.Length(); 
       
  1983             TPtrC8 keyPtr = encoderInfo->Mid( keyStartPosition, keyLength );
       
  1984             key = keyPtr.AllocL();
       
  1985             }
       
  1986         }
       
  1987     
       
  1988     CleanupStack::PopAndDestroy( encoderInfo );
       
  1989     
       
  1990     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::ReadCodecConfigKeyL()" )
       
  1991         
       
  1992     return key;   
       
  1993     }
       
  1994 
       
  1995 // -----------------------------------------------------------------------------
       
  1996 //
       
  1997 // -----------------------------------------------------------------------------
       
  1998 //
       
  1999 void CMusEngMceSession::StoreEncoderConfigInfoL() const
       
  2000     {
       
  2001     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::StoreEncoderConfigInfoL()" )
       
  2002     
       
  2003     HBufC8* configInfoInCenRep = MultimediaSharingSettings::EncoderConfigInfoLC();
       
  2004     __ASSERT_ALWAYS( configInfoInCenRep, User::Leave( KErrNotFound ) );
       
  2005     
       
  2006     TBuf8<NCentralRepositoryConstants::KMaxBinaryLength> keys;
       
  2007     keys.Append( *configInfoInCenRep );
       
  2008     
       
  2009     CMceVideoStream* stream = MusEngMceUtils::GetVideoOutStreamL( *iSession );
       
  2010     const RPointerArray<CMceVideoCodec>& codecs = stream->Codecs();
       
  2011     
       
  2012     for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex )
       
  2013         {
       
  2014         if ( codecs[codecIndex]->SdpName().FindF( KMceSDPNameH264 ) >= 0 )
       
  2015             {
       
  2016             const TPtrC8 keyId = ConfigKeyIdL( *codecs[codecIndex] );
       
  2017             HBufC8* configKey = codecs[codecIndex]->ConfigKeyL();
       
  2018             CleanupStack::PushL( configKey );
       
  2019             
       
  2020             if ( configKey &&
       
  2021                  keys.FindF( keyId ) == KErrNotFound &&
       
  2022                  configInfoInCenRep->FindF( keyId ) == KErrNotFound )
       
  2023                 {
       
  2024                 
       
  2025                 if ( keys.Length() + 
       
  2026                      keyId.Length() + 
       
  2027                      configKey->Length() +
       
  2028                      KMusEncoderInfoTokenizer().Length() <
       
  2029                      NCentralRepositoryConstants::KMaxBinaryLength )
       
  2030                     {
       
  2031                     keys.Append( keyId );                    
       
  2032                     keys.Append( *configKey );
       
  2033                     keys.Append( KMusEncoderInfoTokenizer );
       
  2034                     }
       
  2035                 }
       
  2036                 
       
  2037             CleanupStack::PopAndDestroy( configKey );
       
  2038             }
       
  2039         }
       
  2040     
       
  2041     MultimediaSharingSettings::SetEncoderConfigInfoL( keys );    
       
  2042     
       
  2043     CleanupStack::PopAndDestroy( configInfoInCenRep );
       
  2044         
       
  2045     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::StoreEncoderConfigInfoL()" )
       
  2046     }
       
  2047 
       
  2048 // -----------------------------------------------------------------------------
       
  2049 //
       
  2050 // -----------------------------------------------------------------------------
       
  2051 //
       
  2052 const TPtrC8 CMusEngMceSession::ConfigKeyIdL( 
       
  2053                                     const CMceVideoCodec& aVideoCodec ) const
       
  2054     {
       
  2055     MUS_LOG( "mus: [ENGINE] -> CMusEngMceSession::ConfigKeyIdL()" )
       
  2056     
       
  2057     // Currently works only for AVC
       
  2058     __ASSERT_ALWAYS( aVideoCodec.SdpName().FindF( KMceSDPNameH264 ) >= 0,
       
  2059                      User::Leave( KErrArgument ) );
       
  2060     
       
  2061     TPtrC8 configKeyTokenId;
       
  2062     
       
  2063     if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1 )
       
  2064         {
       
  2065         configKeyTokenId.Set( KMusAvcBitrateLevel1() );
       
  2066         }
       
  2067     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1b )
       
  2068         {
       
  2069         configKeyTokenId.Set( KMusAvcBitrateLevel1b() );
       
  2070         }
       
  2071     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1_1 )
       
  2072         {
       
  2073         configKeyTokenId.Set( KMusAvcBitrateLevel1_1() );
       
  2074         }
       
  2075     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1_2 )
       
  2076         {
       
  2077         configKeyTokenId.Set( KMusAvcBitrateLevel1_2() );
       
  2078         }
       
  2079     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1_3 )
       
  2080         {
       
  2081         configKeyTokenId.Set( KMusAvcBitrateLevel1_3() );
       
  2082         }
       
  2083     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel2 )
       
  2084         {
       
  2085         configKeyTokenId.Set( KMusAvcBitrateLevel2() );
       
  2086         }
       
  2087     else
       
  2088         {
       
  2089         User::Leave( KErrNotFound );
       
  2090         }
       
  2091     
       
  2092     MUS_LOG( "mus: [ENGINE] <- CMusEngMceSession::ConfigKeyIdL()" )
       
  2093 
       
  2094     return configKeyTokenId;
       
  2095     }
       
  2096 
       
  2097 // -----------------------------------------------------------------------------
       
  2098 // Contact address is saved if all following apply:
       
  2099 // - standard variant
       
  2100 // - only one contact entry (mus mgr doesn't provide contact id if multiple
       
  2101 //   contact entries for other end is found)
       
  2102 // - no existing sip address info for contact
       
  2103 // - address is valid sip or tel uri
       
  2104 // -----------------------------------------------------------------------------
       
  2105 //
       
  2106 void CMusEngMceSession::SaveContactL( const TDesC8& /*aAddress*/ )
       
  2107     {
       
  2108     MUS_LOG( "mus: [ENGINE]  -> CMusEngMceSession::SaveContactL" );
       
  2109     
       
  2110     
       
  2111     MUS_LOG( "mus: [ENGINE]  <- CMusEngMceSession::SaveContactL" );
       
  2112     }
       
  2113 
       
  2114 // -----------------------------------------------------------------------------
       
  2115 //
       
  2116 // -----------------------------------------------------------------------------
       
  2117 //
       
  2118 void CMusEngMceSession::StreamStreaming( CMceMediaStream& aStream )
       
  2119     {
       
  2120     if ( aStream.State() == CMceMediaStream::EStreaming &&
       
  2121          aStream.Type() == KMceVideo )
       
  2122         {
       
  2123         MLcVideoPlayer* videoPlayer = NULL;
       
  2124         if ( aStream.Source() && 
       
  2125              aStream.Source()->Type() == KMceRTPSource )
       
  2126             {
       
  2127             videoPlayer = RemoteVideoPlayer();
       
  2128             }
       
  2129         else if ( aStream.Sinks().Count() >= 0 &&
       
  2130                   aStream.Sinks()[0]->Type() == KMceRTPSink )
       
  2131             {
       
  2132             videoPlayer = LocalVideoPlayer();
       
  2133             }
       
  2134         else
       
  2135             {
       
  2136             }
       
  2137         InformObserverAboutPlayerStateChange( videoPlayer );
       
  2138         }
       
  2139     }
       
  2140 
       
  2141 // End of file