mmsharing/mmshengine/src/musenglivesession.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // USER
    19 // USER
    20 #include "musenglivesession.h"
    20 #include "musenglivesession.h"
       
    21 #include "musengsessionobserver.h"
       
    22 #include "musenglivesessionobserver.h"
    21 #include "musunittesting.h"
    23 #include "musunittesting.h"
    22 #include "musengmceutils.h"
    24 #include "musengmceutils.h"
    23 #include "musenglogger.h"
    25 #include "musenglogger.h"
    24 #include "mussessionproperties.h"
    26 #include "mussettings.h"
    25 #include "musenglivevideoplayer.h"
    27 #include "musengorientationhandler.h"
    26 
    28 
    27 // SYSTEM
    29 // SYSTEM
    28 #include <lcsessionobserver.h>
       
    29 #include <mcemanager.h>
    30 #include <mcemanager.h>
    30 #include <mcecamerasource.h>
    31 #include <mcecamerasource.h>
    31 #include <mcevideostream.h>
    32 #include <mcevideostream.h>
    32 #include <mcertpsink.h>
    33 #include <mcertpsink.h>
    33 #include <mcedisplaysink.h>
    34 #include <mcedisplaysink.h>
    35 #include <mcesession.h>
    36 #include <mcesession.h>
    36 #include <mcevideocodec.h>
    37 #include <mcevideocodec.h>
    37 #include <mceh263codec.h>
    38 #include <mceh263codec.h>
    38 #include <mceavccodec.h>
    39 #include <mceavccodec.h>
    39 
    40 
    40 
    41 const TInt KMaxBrightness = 100;
    41 // -----------------------------------------------------------------------------
    42 const TInt KMinBrightness = -100;
    42 //
    43 const TInt KBrightnessStepSize = 10;
    43 // -----------------------------------------------------------------------------
    44 
    44 //
    45 // Names of AVC levels in string for config keys stored in CenRep 
    45 CMusEngLiveSession* CMusEngLiveSession::NewL()
    46 _LIT8( KMusAvcBitrateLevel1, "AvcBrL1=" );
    46     {
    47 _LIT8( KMusAvcBitrateLevel1b, "AvcBrL1b=" );
    47     CMusEngLiveSession* self = new( ELeave )CMusEngLiveSession();
    48 _LIT8( KMusAvcBitrateLevel1_1, "AvcBrL1_1=" );
       
    49 _LIT8( KMusAvcBitrateLevel1_2, "AvcBrL1_2=" );
       
    50 _LIT8( KMusAvcBitrateLevel1_3, "AvcBrL1_3=" );
       
    51 _LIT8( KMusAvcBitrateLevel2, "AvcBrL2=" );
       
    52 
       
    53 _LIT8( KMusEncoderInfoTokenizer, ";" );
       
    54 
       
    55 //Number of big and small zoom steps on Zoom scale
       
    56 const TInt KZoomBigStepCount = 15;
       
    57 const TInt KZoomSmallStepCount = KZoomBigStepCount*2;
       
    58 const TInt KZoomStepMinSize = 1;
       
    59 
       
    60 const TInt64 KZoomFasterTime = 333333; // 1/3 second
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CMusEngLiveSession* CMusEngLiveSession::NewL(
       
    67                         const TDesC& aFileName,
       
    68                         const TRect& aRect,
       
    69                         MMusEngSessionObserver& aSessionObserver,
       
    70                         MMusEngOutSessionObserver& aOutSessionObserver,
       
    71                         MMusEngLiveSessionObserver& aLiveSessionObserver,
       
    72                         TUint aSipProfileId )
       
    73     {
       
    74     CMusEngLiveSession* self = new( ELeave ) CMusEngLiveSession( 
       
    75                                                     aSessionObserver,
       
    76                                                     aOutSessionObserver,
       
    77                                                     aLiveSessionObserver, 
       
    78                                                     aRect,
       
    79                                                     aFileName );
    48     CleanupStack::PushL( self );
    80     CleanupStack::PushL( self );
    49     self->ConstructL();
    81     self->ConstructL( aSipProfileId );
    50     CleanupStack::Pop( self );
    82     CleanupStack::Pop( self );
    51     return self;
    83     return self;
    52     }
    84     }
    53 
    85 
    54 // -----------------------------------------------------------------------------
    86 
    55 //
    87 // -----------------------------------------------------------------------------
    56 // -----------------------------------------------------------------------------
    88 //
    57 //
    89 // -----------------------------------------------------------------------------
    58 CMusEngLiveSession::CMusEngLiveSession()
    90 //
    59     : CMusEngMceOutSession()
    91 EXPORT_C CMusEngLiveSession* CMusEngLiveSession::NewL(
    60     {
    92                         const TRect& aRect,
    61     }
    93                         MMusEngSessionObserver& aSessionObserver,
    62 
    94                         MMusEngOutSessionObserver& aOutSessionObserver,
    63 // -----------------------------------------------------------------------------
    95                         MMusEngLiveSessionObserver& aLiveSessionObserver,
    64 //
    96                         TUint aSipProfileId )
    65 // -----------------------------------------------------------------------------
    97     {
    66 //
    98     CMusEngLiveSession* self = new( ELeave ) CMusEngLiveSession( 
    67 void CMusEngLiveSession::ConstructL()
    99                                                     aSessionObserver,
    68     {
   100                                                     aOutSessionObserver,
    69     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::ConstructL()" )
   101                                                     aLiveSessionObserver, 
    70     
   102                                                     aRect );
    71     iCameraHandler.ReadCameraUsageKeyL();
   103     CleanupStack::PushL( self );
    72     CMusEngMceOutSession::ConstructL();
   104     self->ConstructL( aSipProfileId );
    73     
   105     CleanupStack::Pop( self );
    74     iLiveVideoPlayer = 
   106     return self;
    75         CMusEngLiveVideoPlayer::NewL( *this, iCameraHandler, *this );      
   107     }
    76     
   108 
    77     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::ConstructL()" )
       
    78     }
       
    79 
   109 
    80 // -----------------------------------------------------------------------------
   110 // -----------------------------------------------------------------------------
    81 //
   111 //
    82 // -----------------------------------------------------------------------------
   112 // -----------------------------------------------------------------------------
    83 //
   113 //
    84 CMusEngLiveSession::~CMusEngLiveSession()
   114 CMusEngLiveSession::~CMusEngLiveSession()
    85     {
   115     {
    86     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::~CMusEngLiveSession()" )    
   116     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::~CMusEngLiveSession()" )
    87     delete iLiveVideoPlayer;
   117         
       
   118     delete iOrientationHandler;
       
   119     
    88     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::~CMusEngLiveSession()" )
   120     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::~CMusEngLiveSession()" )
    89     }
   121     }
    90 
   122 
    91 // -----------------------------------------------------------------------------
   123 
    92 // From MLcSession
   124 // -----------------------------------------------------------------------------
    93 // -----------------------------------------------------------------------------
   125 //
    94 //
   126 // -----------------------------------------------------------------------------
    95 MLcVideoPlayer* CMusEngLiveSession::LocalVideoPlayer()
   127 //
    96     {
   128 EXPORT_C TInt CMusEngLiveSession::CurrentZoomL() const
    97     return iLiveVideoPlayer;
   129     {
       
   130     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::CurrentZoomL()" )
       
   131     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   132 
       
   133     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   134 
       
   135     TInt currentZoom = camera->ZoomFactorL() + camera->DigitalZoomFactorL();
       
   136 
       
   137     MUS_LOG1( "mus: [ENGINE]  <- CMusEngLiveSession::CurrentZoomL( %d )",
       
   138               currentZoom )
       
   139 
       
   140     return currentZoom;
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C void CMusEngLiveSession::SetZoomL( TInt aNewZoomFactor )
       
   149     {
       
   150     MUS_LOG1( "mus: [ENGINE]  -> CMusEngLiveSession::SetZoomL( %d )", 
       
   151               aNewZoomFactor )
       
   152               
       
   153     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   154     __ASSERT_ALWAYS( aNewZoomFactor <= MaxZoomL() &&
       
   155                      aNewZoomFactor >= MinZoomL(), 
       
   156                      User::Leave( KErrArgument ) );
       
   157     
       
   158     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   159 
       
   160     if ( aNewZoomFactor < iCameraInfo.iMaxZoom )
       
   161         {
       
   162         MUS_LOG( "mus: [ENGINE]     Optical zoom factor increased" )
       
   163         camera->SetZoomFactorL( aNewZoomFactor ); 
       
   164         }
       
   165     
       
   166     if ( aNewZoomFactor - iCameraInfo.iMaxZoom >= 0 )
       
   167         {
       
   168         camera->SetDigitalZoomFactorL( aNewZoomFactor - iCameraInfo.iMaxZoom );
       
   169         MUS_LOG1( "mus: [ENGINE]     Digital zoom factor increased to %d",
       
   170                   aNewZoomFactor - iCameraInfo.iMaxZoom )
       
   171         }
       
   172     
       
   173     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::SetZoomL()" )
       
   174     }
       
   175 
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 EXPORT_C TInt CMusEngLiveSession::MinZoomL() const
       
   182     {
       
   183     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::MinZoomL()" )
       
   184     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   185 
       
   186     // Although we do not need camera for return value, we have to have it in
       
   187     // order to have proper iCameraInfo
       
   188     MusEngMceUtils::GetCameraL( *iSession );
       
   189 
       
   190     MUS_LOG1( "mus: [ENGINE]  <- CMusEngLiveSession::MinZoomL( %d )",
       
   191               iCameraInfo.iMinZoom )
       
   192 
       
   193     return iCameraInfo.iMinZoom;
       
   194     }
       
   195     
       
   196         
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 EXPORT_C TInt CMusEngLiveSession::MaxZoomL() const
       
   202     {
       
   203     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::MaxZoomL()" )
       
   204     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   205 
       
   206     // Although we do not need camera for return value, we have to have it in
       
   207     // order to have proper iCameraInfo
       
   208     MusEngMceUtils::GetCameraL( *iSession );
       
   209 
       
   210     TInt maxZoom = iCameraInfo.iMaxZoom + iCameraInfo.iMaxDigitalZoom;
       
   211 
       
   212     MUS_LOG1( "mus: [ENGINE]     Max optical zoom( %d )",
       
   213               iCameraInfo.iMaxZoom )
       
   214     MUS_LOG1( "mus: [ENGINE]     Max digital zoom( %d )",
       
   215               iCameraInfo.iMaxDigitalZoom )
       
   216     MUS_LOG1( "mus: [ENGINE]  <- CMusEngLiveSession::MaxZoomL( %d )",
       
   217               maxZoom )
       
   218 
       
   219     return maxZoom;
       
   220     }
       
   221 
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 EXPORT_C void CMusEngLiveSession::ZoomInL()
       
   228     {
       
   229     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::ZoomInL()" )
       
   230     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   231 
       
   232     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   233 
       
   234     // First try to increase optical zoom factor. If in maximum value, try to
       
   235     // increase digital zoom factor.
       
   236     TInt stepSize = ZoomStepSize( iZoomInTime );
       
   237     TInt zoomFactor = camera->ZoomFactorL();
       
   238     TInt zoomDigitalFactor = camera->DigitalZoomFactorL();
       
   239  
       
   240     //increate optical zoom factor
       
   241     if ( zoomFactor + stepSize <= iCameraInfo.iMaxZoom )
       
   242         {
       
   243         //optical zoom factor is enough
       
   244         camera->SetZoomFactorL( zoomFactor + stepSize );
       
   245         stepSize = 0;
       
   246         }
       
   247     else if (zoomFactor <  iCameraInfo.iMaxZoom)
       
   248        {
       
   249             stepSize -=  iCameraInfo.iMaxZoom - zoomFactor;
       
   250             camera->SetZoomFactorL( iCameraInfo.iMaxZoom );
       
   251        }
       
   252 
       
   253     //increate digital zoom factor
       
   254     if (stepSize > 0)
       
   255         {
       
   256         if ( zoomDigitalFactor + stepSize <= iCameraInfo.iMaxDigitalZoom )
       
   257             {
       
   258             camera->SetDigitalZoomFactorL( zoomDigitalFactor + stepSize );
       
   259             }
       
   260         else 
       
   261             {
       
   262             camera->SetDigitalZoomFactorL( iCameraInfo.iMaxDigitalZoom );
       
   263             MUS_LOG( "mus: [ENGINE]     CMusEngLiveSession::ZoomInL(): Optical \
       
   264                              and digital zoom factors are in maximum value" )
       
   265             }
       
   266         }
       
   267     
       
   268     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::ZoomInL()" )
       
   269 
       
   270     }
       
   271 
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 EXPORT_C void CMusEngLiveSession::ZoomOutL()
       
   278     {
       
   279     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::ZoomOutL()" )
       
   280     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   281 
       
   282     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   283 
       
   284     // First try to decrease digital zoom factor. If already zero, try to
       
   285     // decrease optical zoom factor.
       
   286     TInt stepSize = ZoomStepSize( iZoomOutTime );
       
   287     TInt zoomFactor = camera->ZoomFactorL();
       
   288     TInt zoomDigitalFactor = camera->DigitalZoomFactorL();
       
   289     
       
   290     //decreate digital zoom factor firstly
       
   291     if ( zoomDigitalFactor - stepSize >= 0  )
       
   292         {
       
   293         //digital zoom factor is enough
       
   294         camera->SetDigitalZoomFactorL( zoomDigitalFactor - stepSize );
       
   295         stepSize = 0;
       
   296         }
       
   297     else if ( zoomDigitalFactor > 0 )
       
   298         {
       
   299         stepSize -= zoomDigitalFactor;
       
   300         camera->SetDigitalZoomFactorL( 0 );
       
   301         MUS_LOG("mus: [ENGINE] Digigal Factor to zero")
       
   302         }
       
   303    
       
   304     //decreate optical zoom factor firstly
       
   305     if ( stepSize > 0 )
       
   306         {
       
   307         if ( zoomFactor - stepSize > iCameraInfo.iMinZoom )
       
   308             {
       
   309             camera->SetZoomFactorL( zoomFactor - stepSize );
       
   310             }
       
   311         else 
       
   312             {
       
   313             MUS_LOG( "mus: [ENGINE]    CMusEngLiveSession::ZoomOutL(): Optical and \
       
   314                         digital zoom factors are in minimum value" )
       
   315             camera->SetZoomFactorL( iCameraInfo.iMinZoom );
       
   316             }
       
   317         }
       
   318 
       
   319     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::ZoomOutL()" )
       
   320     }
       
   321 
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 EXPORT_C void CMusEngLiveSession::ZoomDefaultL()
       
   328     {
       
   329     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::ZoomDefaultL()" )
       
   330 
       
   331     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   332 
       
   333     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   334 
       
   335     camera->SetZoomFactorL( iDefaultZoomFactor );
       
   336     camera->SetDigitalZoomFactorL( 0 );
       
   337 
       
   338     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::ZoomDefaultL()" )
       
   339     }
       
   340 
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 EXPORT_C void CMusEngLiveSession::SetBrightnessL( TInt aBrightness ) const
       
   347     {
       
   348     MUS_LOG1( "mus: [ENGINE]  -> CMusEngLiveSession::SetBrightnessL( %d )",
       
   349               aBrightness )
       
   350 
       
   351     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   352 
       
   353     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   354     camera->SetBrightnessL( aBrightness );
       
   355 
       
   356     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::SetBrightnessL()" )
       
   357     }
       
   358 
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 EXPORT_C TInt CMusEngLiveSession::CurrentBrightnessL() const
       
   365     {
       
   366     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::CurrentBrightnessL()" )
       
   367     
       
   368     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   369 
       
   370     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   371     TInt currentBrightness = camera->BrightnessL();
       
   372 
       
   373     MUS_LOG1( "mus: [ENGINE]  <- CMusEngLiveSession::CurrentBrightnessL(): %d",
       
   374               currentBrightness )
       
   375 
       
   376     return currentBrightness;
       
   377     }
       
   378 
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 EXPORT_C TInt CMusEngLiveSession::MaxBrightnessL() const
       
   385     {
       
   386     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::MaxBrightnessL()" )
       
   387     
       
   388     // maximum brightness is not in camera info, but a constant 100
       
   389 
       
   390     MUS_LOG1( "mus: [ENGINE]  <- CMusEngLiveSession::MaxBrightnessL(): %d",
       
   391               KMaxBrightness )
       
   392 
       
   393     return KMaxBrightness;
       
   394     }
       
   395 
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 //
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 EXPORT_C TInt CMusEngLiveSession::MinBrightnessL() const
       
   402     {
       
   403     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::MinBrightnessL()" )
       
   404  
       
   405     // maximum brightness is not in camera info, but a constant -100
       
   406 
       
   407     MUS_LOG1( "mus: [ENGINE]  <- CMusEngLiveSession::MinBrightnessL(): %d",
       
   408               KMinBrightness )
       
   409 
       
   410     return KMinBrightness;
       
   411     }
       
   412 
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 EXPORT_C void CMusEngLiveSession::IncreaseBrightnessL()
       
   419     {
       
   420     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::IncreaseBrightnessL()" )
       
   421     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   422 
       
   423     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   424 
       
   425     TInt newBrightness = camera->BrightnessL() + KBrightnessStepSize;
       
   426     
       
   427     if ( newBrightness < KMaxBrightness )
       
   428         {
       
   429         camera->SetBrightnessL( newBrightness );
       
   430         }
       
   431     else
       
   432         {
       
   433         camera->SetBrightnessL( KMaxBrightness );
       
   434         }
       
   435 
       
   436     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::IncreaseBrightnessL()" )
       
   437     }
       
   438 
       
   439 
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 EXPORT_C void CMusEngLiveSession::DecreaseBrightnessL()
       
   445     {
       
   446     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::DecreaseBrightnessL()" )
       
   447     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   448 
       
   449     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   450 
       
   451     TInt newBrightness = camera->BrightnessL() - KBrightnessStepSize;
       
   452 
       
   453     if ( newBrightness > KMinBrightness )
       
   454         {
       
   455         camera->SetBrightnessL( newBrightness );
       
   456         }
       
   457     else
       
   458         {
       
   459         camera->SetBrightnessL( KMinBrightness );
       
   460         }
       
   461 
       
   462     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::DecreaseBrightnessL()" )
       
   463     }
       
   464 
       
   465 
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 // -----------------------------------------------------------------------------
       
   469 //
       
   470 EXPORT_C void CMusEngLiveSession::BrightnessDefaultL()
       
   471     {
       
   472     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::BrightnessDefaultL()" )
       
   473     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   474 
       
   475     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   476 
       
   477     camera->SetBrightnessL( iDefaultBrightness );
       
   478 
       
   479     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::BrightnessDefaultL()" )
       
   480     }
       
   481 
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 //
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 EXPORT_C void CMusEngLiveSession::BrightnessAutoL()
       
   488     {
       
   489     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::BrightnessAutoL()" )
       
   490     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   491 
       
   492     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   493 
       
   494     camera->SetBrightnessL( CCamera::EBrightnessAuto );
       
   495 
       
   496     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::BrightnessAutoL()" )
       
   497     }
       
   498 
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 EXPORT_C void CMusEngLiveSession::RecordL( TBool aRecord )
       
   505     {
       
   506     MUS_LOG1( "mus: [ENGINE]  -> CMusEngLiveSession::RecordL( %d )", aRecord )    
       
   507     
       
   508     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   509 
       
   510     CMceMediaSink* fileSink = MusEngMceUtils::GetMediaSink( *iSession, 
       
   511                                                             KMceFileSink );
       
   512     
       
   513     __ASSERT_ALWAYS( fileSink, User::Leave( KErrNotReady ) );
       
   514     
       
   515     if( aRecord && !fileSink->IsEnabled() )
       
   516         {
       
   517         fileSink->EnableL();        
       
   518         }
       
   519     else if ( !aRecord && fileSink->IsEnabled() )
       
   520         {
       
   521         fileSink->DisableL();        
       
   522         }
       
   523     else
       
   524         {
       
   525         // NOP
       
   526         }
       
   527 
       
   528     MUS_LOG1( "mus: [ENGINE]  <- CMusEngLiveSession::RecordL( %d )", aRecord ) 
       
   529     }    
       
   530 
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 EXPORT_C TBool CMusEngLiveSession::IsRecording()
       
   537     {
       
   538     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::IsRecording()" )    
       
   539     
       
   540     TBool isRecording( EFalse );
       
   541   
       
   542     CMceMediaSink* fileSink = MusEngMceUtils::GetMediaSink( *iSession, 
       
   543                                                             KMceFileSink );
       
   544     if ( fileSink )
       
   545         {
       
   546         isRecording = fileSink->IsEnabled();
       
   547         }
       
   548         
       
   549     MUS_LOG1( "mus: [ENGINE]  <- CMusEngLiveSession::IsRecording(%d)",
       
   550               isRecording )
       
   551                  
       
   552     return isRecording;
       
   553     }
       
   554 
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // Enable camera if not already enabled
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 EXPORT_C void CMusEngLiveSession::PlayL()
       
   561     {
       
   562     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::PlayL()" )
       
   563 
       
   564     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   565     
       
   566     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   567 
       
   568     if ( !camera->IsEnabled() )
       
   569         {
       
   570         camera->EnableL();
       
   571         }
       
   572     else
       
   573         {
       
   574         MUS_LOG( "mus: [ENGINE]    Camera already enabled, ignore request" )
       
   575         }
       
   576     
       
   577     iOrientationHandler->UpdateL();
       
   578         
       
   579     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::PlayL()" )
       
   580     }
       
   581 
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // Disable camera if not already disabled
       
   585 // -----------------------------------------------------------------------------
       
   586 //
       
   587 EXPORT_C void CMusEngLiveSession::PauseL()
       
   588     {
       
   589     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::PauseL()" )
       
   590 
       
   591     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   592 
       
   593     CMceCameraSource* camera = MusEngMceUtils::GetCameraL( *iSession );
       
   594 
       
   595     if ( camera->IsEnabled() )
       
   596         {
       
   597         camera->DisableL();
       
   598         }
       
   599     else
       
   600         {
       
   601         MUS_LOG( "mus: [ENGINE]    Camera already disabled, ignore request" )
       
   602         }
       
   603 
       
   604     iOrientationHandler->UpdateL();
       
   605     
       
   606     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::PauseL()" )
       
   607     }
       
   608 
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 EXPORT_C TBool CMusEngLiveSession::IsPlayingL()
       
   615     {
       
   616     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   617     
       
   618     return ( MusEngMceUtils::GetCameraL( *iSession )->IsEnabled() );
       
   619     }
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 // -----------------------------------------------------------------------------
       
   624 //
       
   625 void CMusEngLiveSession::EnableDisplayL( TBool aEnable )
       
   626 {
       
   627     CMusEngMceSession::EnableDisplayL( aEnable );
       
   628     iOrientationHandler->UpdateL();
       
   629 }
       
   630     
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 // -----------------------------------------------------------------------------
       
   634 //
       
   635 void CMusEngLiveSession::RefreshOrientationL()
       
   636     {
       
   637     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::RefreshOrientationL()" )
       
   638         
       
   639     iOrientationHandler->RefreshOrientationL();
       
   640         
       
   641     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::RefreshOrientationL()" )
       
   642     }
       
   643 
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 // -----------------------------------------------------------------------------
       
   647 //
       
   648 void CMusEngLiveSession::InitializeZoomStepSize()
       
   649     {
       
   650     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::InitializeZoomStepSize()" )
       
   651     
       
   652     iBigZoomStep = ( iCameraInfo.iMaxZoom + iCameraInfo.iMaxDigitalZoom - 
       
   653             iCameraInfo.iMinZoom ) / KZoomBigStepCount;
       
   654             
       
   655     if ( iBigZoomStep < KZoomStepMinSize )
       
   656         iBigZoomStep = KZoomStepMinSize;
       
   657 
       
   658     iSmallZoomStep = ( iCameraInfo.iMaxZoom + iCameraInfo.iMaxDigitalZoom - 
       
   659             iCameraInfo.iMinZoom ) / KZoomSmallStepCount;
       
   660     
       
   661     if ( iSmallZoomStep < KZoomStepMinSize )
       
   662         iSmallZoomStep = KZoomStepMinSize;
       
   663 
       
   664     MUS_LOG2( "mus: [ENGINE]  iSmallZoomStep = %d, iBigZoomStep = %d", 
       
   665             iSmallZoomStep, iBigZoomStep )
       
   666     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::InitializeZoomStepSize()" )   
    98     }
   667     }
    99 
   668 
   100 // -----------------------------------------------------------------------------
   669 // -----------------------------------------------------------------------------
   101 //
   670 //
   102 // -----------------------------------------------------------------------------
   671 // -----------------------------------------------------------------------------
   103 //
   672 //
   104 void CMusEngLiveSession::CompleteSessionStructureL( 
   673 void CMusEngLiveSession::CompleteSessionStructureL( 
   105     CMceStreamBundle& /*aLocalBundle*/ )
   674                                             CMceStreamBundle& /*aLocalBundle*/ )
   106     {
   675     {
   107     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::CompleteSessionStructureL()" )
   676     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::CompleteSessionStructureL()" )
   108 
   677 
   109     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
   678     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
   110 
   679 
   111     iCameraHandler.SetSession( iSession );
       
   112     
       
   113     // Create outgoing video stream
   680     // Create outgoing video stream
   114     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
   681     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
   115     
   682     
   116     CMceRtpSink* rtpsink = CMceRtpSink::NewLC();
   683     CMceRtpSink* rtpsink = CMceRtpSink::NewLC();
   117     videoStream->AddSinkL( rtpsink );
   684     videoStream->AddSinkL( rtpsink );
   118     CleanupStack::Pop( rtpsink );
   685     CleanupStack::Pop( rtpsink );
   119 
   686 
   120     CMceCameraSource* camera = CMceCameraSource::NewLC( *iManager );
   687     CMceCameraSource* camera = CMceCameraSource::NewLC( *iManager );
   121     camera->DisableL(); // Start session in pause mode.
   688     camera->DisableL(); // Start session in pause mode.
   122     
   689     camera->GetCameraInfo( iCameraInfo );
   123     iCameraHandler.InitializeL( *camera );
   690     iDefaultZoomFactor = camera->ZoomFactorL();
       
   691     
       
   692     InitializeZoomStepSize();
   124         
   693         
   125     videoStream->SetSourceL( camera );
   694     videoStream->SetSourceL( camera );
   126     CleanupStack::Pop( camera );
   695     CleanupStack::Pop( camera );
   127 
   696 
   128     iSession->AddStreamL( videoStream );
   697     iSession->AddStreamL( videoStream );
   129     CleanupStack::Pop( videoStream );    
   698     CleanupStack::Pop( videoStream );    
   130 
   699 
   131     // Construct recording stream if needed
   700     // Construct recording stream if needed
   132     if ( iLiveVideoPlayer->LcFileName().Length() > 0 )
   701     if ( iRecordedFile != KNullDesC )
   133         {
   702         {
   134         CMceVideoStream* streamForRecording = CMceVideoStream::NewLC();
   703         CMceVideoStream* streamForRecording = CMceVideoStream::NewLC();
   135         
   704         
   136         CMceFileSink* fileSink = 
   705         CMceFileSink* fileSink = CMceFileSink::NewLC( iRecordedFile );
   137             CMceFileSink::NewLC( iLiveVideoPlayer->LcFileName() );
       
   138         fileSink->DisableL(); // Start in not recording mode
   706         fileSink->DisableL(); // Start in not recording mode
   139         streamForRecording->AddSinkL( fileSink );
   707         streamForRecording->AddSinkL( fileSink );
   140         CleanupStack::Pop( fileSink );
   708         CleanupStack::Pop( fileSink );
   141         
   709         
   142         streamForRecording->SetSourceL( camera );
   710         streamForRecording->SetSourceL( camera );
   143         iSession->AddStreamL( streamForRecording );
   711         iSession->AddStreamL( streamForRecording );
   144         CleanupStack::Pop( streamForRecording );
   712         CleanupStack::Pop( streamForRecording );
   145         }
   713         }
   146     
   714 
   147     iLiveVideoPlayer->SetMceSession( iSession );
       
   148     
       
   149     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::CompleteSessionStructureL()" )
   715     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::CompleteSessionStructureL()" )
   150     }
   716     }
   151 
   717 
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 //
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 void CMusEngLiveSession::HandleSessionStateChanged( 
       
   724                                                 CMceSession& aSession,
       
   725                                                 TInt aStatusCode,
       
   726                                                 const TDesC8& aReasonPhrase )
       
   727     {
       
   728     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::HandleSessionStateChanged" )
       
   729     
       
   730     MUS_ENG_LOG_SESSION_STATE_AND_STATUS( aSession, aStatusCode, aReasonPhrase )
       
   731     
       
   732     if ( iSession && 
       
   733          iSession == &aSession && 
       
   734          aSession.State() == CMceSession::EEstablished &&
       
   735          iStoreEncoderConfigInfo )
       
   736         {
       
   737         iStoreEncoderConfigInfo = EFalse;
       
   738         TRAPD( error, StoreEncoderConfigInfoL() )
       
   739         if ( error != KErrNone && error != KErrNotFound )
       
   740             {
       
   741             // Only acceptable error is absence of repository entry,
       
   742             // otherwise we inform user about failed session.
       
   743             iSessionObserver.SessionFailed();
       
   744             }
       
   745         }
       
   746      
       
   747     CMusEngMceSession::HandleSessionStateChanged( aSession,
       
   748                                                   aStatusCode, 
       
   749                                                   aReasonPhrase );
       
   750     
       
   751     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::HandleSessionStateChanged" )
       
   752     }
       
   753 
       
   754 
   152 // -----------------------------------------------------------------------------
   755 // -----------------------------------------------------------------------------
   153 // Sets video codec attributes
   756 // Sets video codec attributes
   154 // -----------------------------------------------------------------------------
   757 // -----------------------------------------------------------------------------
   155 //
   758 //
   156 void CMusEngLiveSession::AdjustVideoCodecL( CMceVideoCodec& aVideoCodec,
   759 void CMusEngLiveSession::AdjustVideoCodecL( CMceVideoCodec& aVideoCodec )
   157                                             TMceSourceType aSourceType )
       
   158     {
   760     {
   159     MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::AdjustVideoCodecL()" )
   761     MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::AdjustVideoCodecL()" )
   160     
   762     
   161     CMusEngMceOutSession::AdjustVideoCodecL( aVideoCodec, aSourceType );
   763     CMusEngMceOutSession::AdjustVideoCodecL( aVideoCodec );
   162     
   764     
   163     // Starting with 80Kbps  will give better quality than starting with
   765     // Starting with 80Kbps  will give better quality than starting with
   164     // 64kbps.And if network behaves bad than anyhow we will drop down or
   766     // 64kbps.And if network behaves bad than anyhow we will drop down or
   165     // if network is good guy than we climp up to 128. 
   767     // if network is good guy than we climp up to 128. 
   166     // Esp in operator variance. No constant defined in MCE so defining
   768     // Esp in operator variance. No constant defined in MCE so defining
   182     else if ( aVideoCodec.SdpName() == KMceSDPNameH264() )
   784     else if ( aVideoCodec.SdpName() == KMceSDPNameH264() )
   183         {
   785         {
   184         User::LeaveIfError( aVideoCodec.SetAllowedBitrates( 
   786         User::LeaveIfError( aVideoCodec.SetAllowedBitrates( 
   185                                         KMceAvcCodecProfileIdBaseline | 
   787                                         KMceAvcCodecProfileIdBaseline | 
   186                                         KMceAvcCodecProfileIopConstraintSet | 
   788                                         KMceAvcCodecProfileIopConstraintSet | 
   187                                         KMceAvcBitrateLevel1b ) );                           
   789                                         KMceAvcBitrateLevel1b ) );
       
   790         
       
   791         SetCodecConfigKeyL( aVideoCodec );
       
   792         SetEncodingDeviceL( aVideoCodec );                             
   188         }
   793         }
   189     else
   794     else
   190         {
   795         {
   191         // NOP
   796         // NOP
   192         }
   797         }
   193     
   798     
   194     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::AdjustVideoCodecL()" )
   799     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::AdjustVideoCodecL()" )
   195     }
   800     }
   196     
   801     
       
   802     
   197 // -----------------------------------------------------------------------------
   803 // -----------------------------------------------------------------------------
   198 //
   804 //
   199 // -----------------------------------------------------------------------------
   805 // -----------------------------------------------------------------------------
   200 //
   806 //
   201 void CMusEngLiveSession::AdjustAudioCodecL( CMceAudioCodec& aAudioCodec )
   807 void CMusEngLiveSession::AdjustAudioCodecL( CMceAudioCodec& aAudioCodec )
   205     CMusEngMceOutSession::AdjustAudioCodecL( aAudioCodec );
   811     CMusEngMceOutSession::AdjustAudioCodecL( aAudioCodec );
   206     
   812     
   207     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::AdjustAudioCodecL()" )
   813     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::AdjustAudioCodecL()" )
   208     }
   814     }
   209 
   815 
       
   816 
   210 // -----------------------------------------------------------------------------
   817 // -----------------------------------------------------------------------------
   211 //
   818 //
   212 // -----------------------------------------------------------------------------
   819 // -----------------------------------------------------------------------------
   213 //
   820 //
   214 void CMusEngLiveSession::DoCodecSelectionL( CMceVideoStream& aVideoStream )
   821 void CMusEngLiveSession::DoCodecSelectionL( CMceVideoStream& aVideoStream )
   215     {
   822     {
   216     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::DoCodecSelectionL()" )
   823     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::DoCodecSelectionL()" )
   217     
   824     
   218     CMusEngMceSession::DoCodecSelectionL( aVideoStream );
   825     CMusEngMceSession::DoCodecSelectionL( aVideoStream );
   219     
   826     
   220     if ( iVideoCodecList && !IsH264Supported() )
   827     if ( iVideoCodecList &&
       
   828          iVideoCodecList->Length() > 0 &&
       
   829          iVideoCodecList->FindF( KMceSDPNameH264 ) == KErrNotFound )
   221         {        
   830         {        
   222         // We know that recipient doesn't support AVC, so we do not offer it
   831         // We know that recipient doesn't support AVC, so we do not offer it
   223         const RPointerArray<CMceVideoCodec>& codecs = aVideoStream.Codecs();
   832         const RPointerArray<CMceVideoCodec>& codecs = aVideoStream.Codecs();
   224     
   833     
   225         for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex )
   834         for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex )
   234             }
   843             }
   235         }
   844         }
   236      
   845      
   237     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::DoCodecSelectionL()" )
   846     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::DoCodecSelectionL()" )
   238     }
   847     }
       
   848     
   239 
   849 
   240 // -----------------------------------------------------------------------------
   850 // -----------------------------------------------------------------------------
   241 //
   851 //
   242 // -----------------------------------------------------------------------------
   852 // -----------------------------------------------------------------------------
   243 //
   853 //
   252         }
   862         }
   253     
   863     
   254     MUS_ENG_LOG_STREAM_STATE( aStream )
   864     MUS_ENG_LOG_STREAM_STATE( aStream )
   255     
   865     
   256     CMceVideoStream* recordingStream = 
   866     CMceVideoStream* recordingStream = 
   257         MusEngMceUtils::GetRecordingStream( *iSession );
   867                             MusEngMceUtils::GetRecordingStream( *iSession );
   258     
   868     
   259     if ( recordingStream &&
   869     if ( recordingStream &&
   260          recordingStream == &aStream &&
   870          recordingStream == &aStream &&
   261          aStream.State() == CMceMediaStream::ENoResources &&
   871          aStream.State() == CMceMediaStream::ENoResources &&
   262          aSink.IsEnabled() == EFalse )
   872          aSink.IsEnabled() == EFalse )
   263         {
   873         {
   264         InformObserverAboutSessionFailure( MLcSession::EDiskFull );
   874         iLiveSessionObserver.DiskFull();
   265         }
   875         }
   266     else
   876     else
   267         {
   877         {
   268         // Cannot handle, forward to a base class
   878         // Cannot handle, forward to a base class
   269         CMusEngMceSession::StreamStateChanged( aStream, aSink );
   879         CMusEngMceSession::StreamStateChanged( aStream, aSink );
   270         }
   880         }
   271     
   881     
   272     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::StreamStateChanged( sink )" )
   882     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::StreamStateChanged( sink )" )
   273     }
   883     }
       
   884     
       
   885 
       
   886 // -----------------------------------------------------------------------------
       
   887 //
       
   888 // -----------------------------------------------------------------------------
       
   889 //
       
   890 CMusEngLiveSession::CMusEngLiveSession(
       
   891                         MMusEngSessionObserver& aSessionObserver,
       
   892                         MMusEngOutSessionObserver& aOutSessionObserver,
       
   893                         MMusEngLiveSessionObserver& aLiveSessionObserver,
       
   894                         const TRect& aRect,
       
   895                         const TDesC& aRecordedFile )
       
   896     : CMusEngMceOutSession( aRect,
       
   897                             aSessionObserver,
       
   898                             aOutSessionObserver ),
       
   899       iLiveSessionObserver( aLiveSessionObserver ),
       
   900       iDefaultZoomFactor( -1 ),
       
   901       iDefaultBrightness( 0 ),
       
   902       iRecordedFile( aRecordedFile ),
       
   903       iZoomInTime(0),
       
   904       iZoomOutTime(0),
       
   905       iSmallZoomStep( KZoomStepMinSize ),
       
   906       iBigZoomStep( KZoomStepMinSize )
       
   907     {
       
   908     }
       
   909 
       
   910 
       
   911 // -----------------------------------------------------------------------------
       
   912 //
       
   913 // -----------------------------------------------------------------------------
       
   914 //
       
   915 void CMusEngLiveSession::ConstructL( TUint aSipProfileId )
       
   916     {
       
   917     MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::ConstructL()" )
       
   918 
       
   919     CMusEngMceOutSession::ConstructL( aSipProfileId );
       
   920 
       
   921     iOrientationHandler = CMusEngOrientationHandler::NewL( *this, iLiveSessionObserver );
       
   922     
       
   923     MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::ConstructL()" )
       
   924     }
       
   925 
       
   926 
       
   927 // -----------------------------------------------------------------------------
       
   928 //
       
   929 // -----------------------------------------------------------------------------
       
   930 //
       
   931 void CMusEngLiveSession::SetEncodingDeviceL( CMceVideoCodec& aVideoCodec )
       
   932     {
       
   933     MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::SetEncodingDeviceL()" )
       
   934 
       
   935     // We try to read encoding device UID. If we do not succeed, we use default
       
   936     
       
   937     const TUid KDefaultEncodingDevice( TUid::Uid( 0x20001C13 ) );
       
   938     TUid encodingDevice( KDefaultEncodingDevice );
       
   939     TRAPD( error, 
       
   940            encodingDevice = MultimediaSharingSettings::EncodingDeviceL() )
       
   941     __ASSERT_ALWAYS( error == KErrNone || error == KErrNotFound, 
       
   942                      User::Leave( error ) );
       
   943     aVideoCodec.SetPreferredEncodingDecodingDeviceL( encodingDevice );
       
   944     
       
   945     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::SetEncodingDeviceL()" )
       
   946     }
       
   947     
       
   948 
       
   949 // -----------------------------------------------------------------------------
       
   950 //
       
   951 // -----------------------------------------------------------------------------
       
   952 //
       
   953 void CMusEngLiveSession::SetCodecConfigKeyL( CMceVideoCodec& aVideoCodec )
       
   954     {
       
   955     MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::SetCodecConfigKeyL()" )
       
   956     
       
   957     HBufC8* configKey( NULL );
       
   958         
       
   959     // We try to read config key. If we do not succeed, we prepare to
       
   960     // write keys to CenRep for the next time.
       
   961     TRAPD( error, configKey = ReadCodecConfigKeyL( aVideoCodec ) )
       
   962     
       
   963     if ( error == KErrNone )
       
   964         {
       
   965         // There is a repository for config keys
       
   966         if ( configKey )
       
   967             {
       
   968             // ...and key is found.
       
   969             CleanupStack::PushL( configKey );
       
   970             aVideoCodec.SetConfigKeyL( *configKey );
       
   971             CleanupStack::PopAndDestroy( configKey );
       
   972             }
       
   973         else
       
   974             {
       
   975             // ...but key is not found, so it must be written to CenRep when
       
   976             // available. 
       
   977             iStoreEncoderConfigInfo = ETrue;
       
   978             }
       
   979         }
       
   980     else if ( error == KErrNotFound )
       
   981         {
       
   982         // There is no repository for config keys so there is no point
       
   983         // trying to write anything there. Session setup can still continue.
       
   984         MUS_LOG1( "mus: [ENGINE]    No repository for config keys [%d]", error )
       
   985         }            
       
   986     else
       
   987         {
       
   988         User::Leave( error );
       
   989         }
       
   990     
       
   991     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::SetCodecConfigKeyL()" )
       
   992     }
       
   993 
       
   994 
       
   995 // -----------------------------------------------------------------------------
       
   996 //
       
   997 // -----------------------------------------------------------------------------
       
   998 //
       
   999 HBufC8* CMusEngLiveSession::ReadCodecConfigKeyL( 
       
  1000                                     const CMceVideoCodec& aVideoCodec ) const
       
  1001     {
       
  1002     MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::ReadCodecConfigKeyL()" )
       
  1003     
       
  1004     HBufC8* key( NULL );
       
  1005  
       
  1006     HBufC8* encoderInfo = MultimediaSharingSettings::EncoderConfigInfoLC();
       
  1007     __ASSERT_ALWAYS( encoderInfo, User::Leave( KErrNotFound ) );
       
  1008     
       
  1009     TPtrC8 keyId( ConfigKeyIdL( aVideoCodec ) ); 
       
  1010     
       
  1011     TInt tokenStartPosition( encoderInfo->FindC( keyId ) );
       
  1012     if ( tokenStartPosition > KErrNotFound )
       
  1013         {
       
  1014         TInt tokenLength( encoderInfo->Mid( tokenStartPosition ).FindC( 
       
  1015                                                 KMusEncoderInfoTokenizer ) );
       
  1016         if ( tokenLength > KErrNotFound )
       
  1017             {
       
  1018             // Separate key from token by removing keyId
       
  1019             TInt keyStartPosition = tokenStartPosition + keyId.Length();
       
  1020             TInt keyLength = tokenLength - keyId.Length(); 
       
  1021             TPtrC8 keyPtr = encoderInfo->Mid( keyStartPosition, keyLength );
       
  1022             key = keyPtr.AllocL();
       
  1023             }
       
  1024         }
       
  1025     
       
  1026     CleanupStack::PopAndDestroy( encoderInfo );
       
  1027     
       
  1028     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::ReadCodecConfigKeyL()" )
       
  1029         
       
  1030     return key;   
       
  1031     }
       
  1032     
       
  1033 
       
  1034 // -----------------------------------------------------------------------------
       
  1035 //
       
  1036 // -----------------------------------------------------------------------------
       
  1037 //
       
  1038 void CMusEngLiveSession::StoreEncoderConfigInfoL() const
       
  1039     {
       
  1040     MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::StoreEncoderConfigInfoL()" )
       
  1041     
       
  1042     HBufC8* configInfoInCenRep = MultimediaSharingSettings::EncoderConfigInfoLC();
       
  1043     __ASSERT_ALWAYS( configInfoInCenRep, User::Leave( KErrNotFound ) );
       
  1044     
       
  1045     TBuf8<NCentralRepositoryConstants::KMaxBinaryLength> keys;
       
  1046     keys.Append( *configInfoInCenRep );
       
  1047     
       
  1048     CMceVideoStream* stream = MusEngMceUtils::GetVideoOutStreamL( *iSession );
       
  1049     const RPointerArray<CMceVideoCodec>& codecs = stream->Codecs();
       
  1050     
       
  1051     for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex )
       
  1052         {
       
  1053         if ( codecs[codecIndex]->SdpName().FindF( KMceSDPNameH264 ) >= 0 )
       
  1054             {
       
  1055             const TPtrC8 keyId = ConfigKeyIdL( *codecs[codecIndex] );
       
  1056             HBufC8* configKey = codecs[codecIndex]->ConfigKeyL();
       
  1057             CleanupStack::PushL( configKey );
       
  1058             
       
  1059             if ( configKey &&
       
  1060                  keys.FindF( keyId ) == KErrNotFound &&
       
  1061                  configInfoInCenRep->FindF( keyId ) == KErrNotFound )
       
  1062                 {
       
  1063                 
       
  1064                 if ( keys.Length() + 
       
  1065                      keyId.Length() + 
       
  1066                      configKey->Length() +
       
  1067                      KMusEncoderInfoTokenizer().Length() <
       
  1068                      NCentralRepositoryConstants::KMaxBinaryLength )
       
  1069                     {
       
  1070                     keys.Append( keyId );                    
       
  1071                     keys.Append( *configKey );
       
  1072                     keys.Append( KMusEncoderInfoTokenizer );
       
  1073                     }
       
  1074                 }
       
  1075                 
       
  1076             CleanupStack::PopAndDestroy( configKey );
       
  1077             }
       
  1078         }
       
  1079     
       
  1080     MultimediaSharingSettings::SetEncoderConfigInfoL( keys );    
       
  1081     
       
  1082     CleanupStack::PopAndDestroy( configInfoInCenRep );
       
  1083         
       
  1084     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::StoreEncoderConfigInfoL()" )
       
  1085     }
       
  1086 
       
  1087 
       
  1088 // -----------------------------------------------------------------------------
       
  1089 //
       
  1090 // -----------------------------------------------------------------------------
       
  1091 //
       
  1092 const TPtrC8 CMusEngLiveSession::ConfigKeyIdL(
       
  1093                                     const CMceVideoCodec& aVideoCodec ) const
       
  1094     {
       
  1095     MUS_LOG( "mus: [ENGINE] -> CMusEngLiveSession::ConfigKeyIdL()" )
       
  1096     
       
  1097     // Currently works only for AVC
       
  1098     __ASSERT_ALWAYS( aVideoCodec.SdpName().FindF( KMceSDPNameH264 ) >= 0,
       
  1099                      User::Leave( KErrArgument ) );
       
  1100     
       
  1101     TPtrC8 configKeyTokenId;
       
  1102     
       
  1103     if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1 )
       
  1104         {
       
  1105         configKeyTokenId.Set( KMusAvcBitrateLevel1() );
       
  1106         }
       
  1107     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1b )
       
  1108         {
       
  1109         configKeyTokenId.Set( KMusAvcBitrateLevel1b() );
       
  1110         }
       
  1111     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1_1 )
       
  1112         {
       
  1113         configKeyTokenId.Set( KMusAvcBitrateLevel1_1() );
       
  1114         }
       
  1115     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1_2 )
       
  1116         {
       
  1117         configKeyTokenId.Set( KMusAvcBitrateLevel1_2() );
       
  1118         }
       
  1119     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel1_3 )
       
  1120         {
       
  1121         configKeyTokenId.Set( KMusAvcBitrateLevel1_3() );
       
  1122         }
       
  1123     else if ( aVideoCodec.AllowedBitrates() & KMceAvcBitrateLevel2 )
       
  1124         {
       
  1125         configKeyTokenId.Set( KMusAvcBitrateLevel2() );
       
  1126         }
       
  1127     else
       
  1128         {
       
  1129         User::Leave( KErrNotFound );
       
  1130         }
       
  1131     
       
  1132     MUS_LOG( "mus: [ENGINE] <- CMusEngLiveSession::ConfigKeyIdL()" )
       
  1133 
       
  1134     return configKeyTokenId;
       
  1135     }
       
  1136 
       
  1137 
       
  1138 // -----------------------------------------------------------------------------
       
  1139 //  Calculate the zoom step based time escaped
       
  1140 // -----------------------------------------------------------------------------
       
  1141 TInt CMusEngLiveSession::ZoomStepSize( TInt64& aTime )
       
  1142     {
       
  1143 //    MUS_LOG( "mus: [ENGINE]  -> CMusEngLiveSession::ZoomStepSize()" )    
       
  1144     TTime now;
       
  1145     now.HomeTime();
       
  1146     TInt64 timeNow = now.Int64();   
       
  1147     TInt stepSize = ( ( timeNow - aTime ) <= KZoomFasterTime ) ? iBigZoomStep : iSmallZoomStep;
       
  1148     
       
  1149     aTime = now.Int64();
       
  1150     
       
  1151     MUS_LOG1( "mus: [ENGINE]  stepSize = %d", stepSize );    
       
  1152 //    MUS_LOG( "mus: [ENGINE]  <- CMusEngLiveSession::ZoomStepSize()" )
       
  1153     return stepSize;
       
  1154     }
       
  1155 
       
  1156