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