vtengines/videoteleng/Src/Media/CVtEngMediaHandler.cpp
changeset 0 ed9695c8bcbe
child 12 3e521e99f813
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2004-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of video session interface.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CVtEngMediaHandler.h"
       
    21 #include    "CVtEngLocalVideo.h"
       
    22 #include    "CVtEngRemoteVideo.h"
       
    23 #include    "MVtEngFrameObserver.h"
       
    24 #include    "CVtEngStateManager.h"
       
    25 #include    "CVtEngOperation.h"
       
    26 #include    "TVtEngRendering.h"
       
    27 #include    "TVtEngRenderingDSA.h"
       
    28 #include    "TVtEngRenderingDP.h"
       
    29 #include    "TVtEngRenderingNGA.h"
       
    30 #include    "VtEngUtils.h"
       
    31 #include    "CVtEngInitializer.h"
       
    32 #include    "CVtEngEventManager.h"
       
    33 #include    "CVtEngSettings.h"
       
    34 #include    "CVtEngHandlerContainer.h"
       
    35 #include    "MVtEngDtmfHandler.h"
       
    36 #include    "cvtengmdtrcommandsender.h"
       
    37 #include    "VtEngPanic.h"
       
    38 #include    <sysutil.h>
       
    39 #include    <cvtlogger.h>
       
    40 #include    <mvtprotocolhandler.h>
       
    41 #include    <e32des8.h>
       
    42 #include    <videotelephonyvariant.hrh>
       
    43 #include    <es_sock.h> // BigEndian
       
    44 
       
    45 #include    <mvtengcamerapreferences.h>
       
    46 #include    "cvtengrecord2file.h"
       
    47 
       
    48 // MACROS
       
    49 #ifdef VTDEBUG
       
    50 // In debug mode sinks and sources are not necessarily added.
       
    51 #define ADD_VIDEO_SINK { \
       
    52     if ( DEBUG_CFG_NO_VIDEO_SINK == 0 )  { AddVideoSink(); } }
       
    53 #define ADD_VIDEO_SOURCE { \
       
    54     if ( DEBUG_CFG_NO_VIDEO_SOURCE == 0 )  { AddVideoSource(); } }
       
    55 #define ADD_AUDIO_SOURCE \
       
    56     { if ( DEBUG_CFG_NO_AUDIO_SOURCE == 0 )  { AddAudioSource(); } }
       
    57 #define ADD_AUDIO_SINK \
       
    58     { if ( DEBUG_CFG_NO_AUDIO_SINK == 0 )  { AddAudioSink(); } }
       
    59 #else
       
    60 // In release mode they are added.
       
    61 #define ADD_VIDEO_SINK AddVideoSink();
       
    62 #define ADD_VIDEO_SOURCE AddVideoSource();
       
    63 #define ADD_AUDIO_SOURCE AddAudioSource();
       
    64 #define ADD_AUDIO_SINK AddAudioSink();
       
    65 #endif // VTDEBUG
       
    66 
       
    67 // CONSTANTS
       
    68 const TInt KVtEngOperationArraySize     = 2;
       
    69 // System version string buffer length.
       
    70 const TInt KVtEngSwVersionTextLength    = KSysUtilVersionTextLength;
       
    71 // Country code for version information.
       
    72 const TUint8 KVtEngCountryCodeForProto     = 60;
       
    73 // Extension code for version information (unknown).
       
    74 const TUint8 KVtEngExtensionForProto       = 0;
       
    75 // Manufacturer code for version information (unknown).
       
    76 const TUint32 KVtEngManufacturerForProto   = 0;
       
    77 // Timer to detect too long disconnect.
       
    78 const TInt KVtEngDisconnectionTimer = 20000000;
       
    79 // Space character constant.
       
    80 const TText KVtEngCharacterSpace( ' ' );
       
    81 // New line (\n) character constant.
       
    82 const TInt KVtEngCharacterEndLine( 10 );
       
    83 
       
    84 // Multiplex delay in milliseconds
       
    85 const TInt KVtEngMultiplexingDelay = 150;
       
    86 
       
    87 // TradeOff values
       
    88 const TInt KVtEngTradeOffDetailMax = 9;
       
    89 const TInt KVtEngTradeOffNormalMax = 19;
       
    90 const TInt KVtEngTradeOffMotionMax = 31;
       
    91 
       
    92 // ============================ MEMBER FUNCTIONS ===============================
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CVtEngMediaHandler::CVtEngMediaHandler
       
    96 // C++ constructor can NOT contain any code, that
       
    97 // might leave.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CVtEngMediaHandler::CVtEngMediaHandler() :
       
   101     iProtoState( MVtProtocolCommand::EIdle ),
       
   102     iAudioCtrl(0),
       
   103     iProtoMaxVolume(0),
       
   104     iTempProviderInfo( CVtEngLocalVideo::KVtEngProviderNone ),
       
   105     iH324Config( 0 ),
       
   106     iH263Encoder( 0 )
       
   107     {
       
   108     if ( CVtEngUtility::Settings().IsDefaultStillImageDefined() )
       
   109         {
       
   110         iTempProviderInfo = CVtEngLocalVideo::KVtEngProviderDefaultStillImage;
       
   111         }
       
   112 
       
   113     // Check is AMR-WB supported or not in platform. Adjusted using local
       
   114     // variation.
       
   115     if ( CVtEngUtility::Settings().CheckBits( KVTLVFlagEnableAMR_WB ) )
       
   116         {
       
   117         __VTPRINT( DEBUG_MEDIA | DEBUG_CONSTRUCT, "MH.c++ AMR-WB set ON" )
       
   118         iSdkInitInfo.iAMRWBOn = ETrue;
       
   119         }
       
   120     else
       
   121         {
       
   122         __VTPRINT( DEBUG_MEDIA | DEBUG_CONSTRUCT, "MH.c++ AMR-WB set OFF" )
       
   123         iSdkInitInfo.iAMRWBOn = EFalse;
       
   124         }
       
   125         
       
   126     if ( CVtEngUtility::Settings().CheckBits( KVTLVFlagDisableMpeg4 ) )
       
   127         {
       
   128         __VTPRINT( DEBUG_MEDIA | DEBUG_CONSTRUCT, "MH.c++ Mpeg4  set OFF" )
       
   129         iSdkInitInfo.iDisableMpeg4 = ETrue;        
       
   130         }
       
   131     else
       
   132         {
       
   133         __VTPRINT( DEBUG_MEDIA | DEBUG_CONSTRUCT, "MH.c++ Mpeg4  set ON" )
       
   134         iSdkInitInfo.iDisableMpeg4 = EFalse;
       
   135         }
       
   136 
       
   137     __VTPRINT( DEBUG_MEDIA | DEBUG_CONSTRUCT, "MH.c++" )
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CVtEngMediaHandler::ConstructL
       
   142 // Symbian 2nd phase constructor can leave.
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CVtEngMediaHandler::ConstructL()
       
   146     {
       
   147     __VTPRINTENTER( "MH.ConstructL" )
       
   148 
       
   149     iAsyncCallback = CIdle::NewL( CActive::EPriorityHigh );
       
   150     iPendingOps = new ( ELeave)
       
   151         CArrayFixFlat<TCmdOpPair>( KVtEngOperationArraySize );
       
   152     iPendingOps->SetReserveL( KVtEngOperationArraySize );
       
   153     
       
   154     __VTPRINT2( DEBUG_MEDIA, "DebugFlags used are %d", CVtLogger::Flags() )
       
   155 
       
   156     iLocalVideo = CVtEngLocalVideo::NewL( *this );
       
   157     __VTPRINTEXIT( "MH.ConstructL" )
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CVtEngMediaHandler::NewL
       
   162 // Two-phased constructor.
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 CVtEngMediaHandler* CVtEngMediaHandler::NewL()
       
   166     {
       
   167     CVtEngMediaHandler* self = new( ELeave )CVtEngMediaHandler();
       
   168     CleanupStack::PushL( self );
       
   169     self->ConstructL();
       
   170     CleanupStack::Pop();
       
   171     return self;
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CVtEngMediaHandler::~CVtEngMediaHandler
       
   176 // Destructor. Cannot leave.
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 CVtEngMediaHandler::~CVtEngMediaHandler()
       
   180     {
       
   181     __VTPRINTENTER( "MH.~" )
       
   182     if ( iPendingOps )
       
   183         {
       
   184         iPendingOps->Reset(); // Make sure this is empty
       
   185         delete iPendingOps;
       
   186         }
       
   187     delete iPendingOp;
       
   188     delete iTimer;
       
   189     delete iAsyncCallback;
       
   190     delete iLocalVideo;
       
   191     delete iRemoteVideo;
       
   192     __VTPRINTEXIT( "MH.~" )
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CVtEngMediaHandler::GetMediaState
       
   197 // Returns media state.
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TInt CVtEngMediaHandler::GetMediaState(
       
   201     const TMediaDirection aMediaDirection,
       
   202     TInt& aActiveMedia ) const
       
   203     {
       
   204     __VTPRINT2( DEBUG_MEDIA, "MH.GetMediaState direction=%d", aMediaDirection )
       
   205     aActiveMedia = 0;
       
   206     switch ( aMediaDirection )
       
   207         {
       
   208         case EMediaOutgoing:
       
   209             {
       
   210             const TInt result( iLocalVideo->GetMediaState( aActiveMedia ) );
       
   211             if ( !IsFlag( EOutVideoChannelClosed ) )
       
   212                 {
       
   213                 aActiveMedia |= EMediaVideoChannelOpen;
       
   214                 }
       
   215             if ( !IsFlag( EOutAudioChannelClosed ) )
       
   216                 {
       
   217                 aActiveMedia |= EMediaAudioChannelOpen;
       
   218                 }
       
   219             return result;
       
   220             }
       
   221 
       
   222         case EMediaIncoming:
       
   223             aActiveMedia = iRemoteMediaState;
       
   224             if ( ( iRemoteVideo && !iRemoteVideo->GetDsaState() ) )
       
   225                 {
       
   226                 aActiveMedia &= (~EMediaVideo);
       
   227                 }
       
   228             __VTPRINT2( DEBUG_MEDIA, "MH.remoteState=%d", aActiveMedia )
       
   229             return KErrNone;
       
   230 
       
   231         default:
       
   232             break;
       
   233         }
       
   234     return KErrNotSupported;
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CVtEngMediaHandler::RenderingStarted
       
   239 // Returns the state of video.
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 TBool CVtEngMediaHandler::RenderingStarted(
       
   243     const TMediaDirection aDirection ) const
       
   244     {
       
   245     __VTPRINT2( DEBUG_MEDIA, "MH.RS %d", aDirection )
       
   246     TBool started( EFalse );
       
   247     if( aDirection == EMediaOutgoing )
       
   248         {
       
   249         started = iLocalVideo->ViewFinderStarted();
       
   250         }
       
   251     else // EMediaIncoming
       
   252         {
       
   253         started = iRemoteVideo->GetDsaState();
       
   254         }
       
   255 
       
   256     __VTPRINT2( DEBUG_MEDIA, "MH.RS started %d", started )
       
   257     return started;
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CVtEngMediaHandler::GetSource
       
   262 // Returns active source.
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 TInt CVtEngMediaHandler::GetSource( TMediaSource& aSource ) const
       
   266     {
       
   267     TInt err( KErrNotReady );
       
   268     if ( iLocalVideo )
       
   269         {
       
   270         aSource = iLocalVideo->GetMediaSource();
       
   271         err = KErrNone;
       
   272         }
       
   273     return err;
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CVtEngMediaHandler::GetSourcesCaps
       
   278 // Returns source selection capabilities.
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 TInt CVtEngMediaHandler::GetSourcesCaps( TInt& aCaps ) const
       
   282     {
       
   283     TInt err( KErrNotReady );
       
   284     if ( iLocalVideo )
       
   285         {
       
   286         err = iLocalVideo->GetSourceCaps( aCaps );
       
   287         }
       
   288     return err;
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CVtEngMediaHandler::GetCurrentCameraId
       
   293 // Returns current camera.
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 TInt CVtEngMediaHandler::GetCurrentCameraId( TCameraId& aId ) const
       
   297     {
       
   298     __VTPRINT( DEBUG_GEN, "MH.GetCurrentCameraId")
       
   299     aId = iSelectedCameraId;
       
   300     TInt err( KErrNotReady );
       
   301 
       
   302     TBool initialized( EFalse );
       
   303     err = iLocalVideo->IsInitialized( aId, initialized );
       
   304     if ( !initialized && ( err != KErrInUse ) )
       
   305         {
       
   306         __VTPRINT2( DEBUG_GEN, "MH.GetCurrentCameraId err=%d", KErrNotReady )
       
   307         return KErrNotReady;
       
   308         }
       
   309     __VTPRINT2( DEBUG_GEN, "MH.GetCurrentCameraId initialized err=%d", err )
       
   310     return err;//Not initialized
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CVtEngMediaHandler::GetCameraInfo
       
   315 // Returns camera information.
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 TInt CVtEngMediaHandler::GetCameraInfo(
       
   319     const TCameraId aId, TCameraInfo& aInfo ) const
       
   320     {
       
   321     return iLocalVideo->GetCameraInfo( aId, aInfo );
       
   322     }
       
   323 
       
   324 // -----------------------------------------------------------------------------
       
   325 // CVtEngMediaHandler::GetCurrentZoomStep
       
   326 // Returns current zooming.
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 TInt CVtEngMediaHandler::GetCurrentZoomStep( TInt& aCurrentStep )
       
   330     {
       
   331     return iLocalVideo->GetDigitalZoomFactor( aCurrentStep );
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CVtEngMediaHandler::GetMaxZoomStep
       
   336 // Returns maximum zooming.
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 TInt CVtEngMediaHandler::GetMaxZoomStep( TInt& aMaxZoomStep )
       
   340     {
       
   341     return iLocalVideo->GetMaxDigitalZoomStep( aMaxZoomStep );
       
   342     }
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // CVtEngMediaHandler::GetMajorZoomStepCount
       
   346 // Gets number of major zoom level leaps.
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 TInt CVtEngMediaHandler::GetMajorZoomStepCount( TInt& aCount )
       
   350     {
       
   351     return iLocalVideo->GetMajorDigitalZoomStepCount( aCount );
       
   352     }
       
   353 
       
   354 // -----------------------------------------------------------------------------
       
   355 // CVtEngMediaHandler::GetMajorZoomStep
       
   356 // Maps major zoom leap step to corresponding step index.
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 void CVtEngMediaHandler::GetMajorZoomStep( TInt aIndex, TInt& aStep )
       
   360     {
       
   361     if ( iLocalVideo )
       
   362         {
       
   363         iLocalVideo->GetMajorDigitalZoomStep( aIndex, aStep );
       
   364         }
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CVtEngMediaHandler::GetFreezeSupported
       
   369 // Maps major zoom leap step to corresponding step index.
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 TInt CVtEngMediaHandler::GetFreezeSupported( TBool& aFreezeSupported) const
       
   373     {
       
   374     if ( iLocalVideo )
       
   375         {
       
   376         return iLocalVideo->GetFreezeSupported( aFreezeSupported );
       
   377         }
       
   378     return KErrNotReady;
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CVtEngMediaHandler::GetFreezeState
       
   383 // Returns KErrNotReady if provider is not ready yet. If KErrNone is returned
       
   384 // then aFrozen will be ETrue if the provider is frozen, EFalse otherwise.
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 TInt CVtEngMediaHandler::GetFreezeState( TBool& aFrozen ) const
       
   388     {
       
   389     if ( iLocalVideo )
       
   390         {
       
   391         aFrozen = iLocalVideo->IsFrozen();
       
   392         return KErrNone;
       
   393         }
       
   394     return KErrNotReady;
       
   395     }
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 // CVtEngMediaHandler::GetDsaState
       
   399 // Returns media state.
       
   400 // -----------------------------------------------------------------------------
       
   401 //
       
   402 TInt CVtEngMediaHandler::GetDsaState(
       
   403     const TMediaDirection aMediaDirection,
       
   404     TBool& aActive ) const
       
   405     {
       
   406     if ( !iRemoteVideo )
       
   407         {
       
   408         return KErrNotReady;
       
   409         }
       
   410     switch ( aMediaDirection )
       
   411         {
       
   412         case EMediaOutgoing:
       
   413             break;
       
   414         case EMediaIncoming:
       
   415             aActive = iRemoteVideo->GetDsaState();
       
   416             return KErrNone;
       
   417         default:
       
   418             break;
       
   419         }
       
   420     return KErrNotSupported;
       
   421     }
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CVtEngMediaHandler::VideoCallConnected
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 TBool CVtEngMediaHandler::VideoCallConnected () const
       
   428 	  {
       
   429     TBool connected = EFalse;
       
   430     if ( MVtProtocolCommand::EConnected == iProtoState )
       
   431         {
       
   432     	  connected = ETrue;
       
   433         }
       
   434     return connected;
       
   435     }
       
   436     
       
   437 // -----------------------------------------------------------------------------
       
   438 // CVtEngMediaHandler::GetVideoQuality
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 void CVtEngMediaHandler::GetVideoQuality( TVideoQuality& aVideoQuality ) const
       
   442     {
       
   443     __VTPRINTENTER( "MH.GetVideoQuality" )
       
   444     aVideoQuality = iVideoQuality.VideoQuality();
       
   445     __VTPRINTEXIT( "MH.GetVideoQuality" )
       
   446     }
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CVtEngMediaHandler::GetObjectSharingState
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CVtEngMediaHandler::GetObjectSharingState(
       
   453     TShareObjectState& aObjectSharingState ) const
       
   454     {
       
   455     __VTPRINTENTER( "MH.GetObjectSharingState" )
       
   456     if( iProtoState == MVtProtocolCommand::EConnected )
       
   457         {
       
   458         iLocalVideo->GetObjectSharingState( aObjectSharingState );
       
   459         }
       
   460     else
       
   461         {
       
   462         aObjectSharingState = ENotAbleToShare;
       
   463         }
       
   464     __VTPRINTEXIT( "MH.GetObjectSharingState" )
       
   465     }
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // CVtEngMediaHandler::GetCameraOrientations
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 void CVtEngMediaHandler::GetCameraOrientations(
       
   472     TCameraOrientation& aPrimaryCameraOrientation,
       
   473     TCameraOrientation& aSecondaryCameraOrientation ) const
       
   474     {
       
   475     __VTPRINTENTER( "MH.GetCameraOrientations" )
       
   476     CVtEngSettings& settings = CVtEngUtility::Settings();
       
   477     settings.GetCameraOrientations( aPrimaryCameraOrientation,
       
   478         aSecondaryCameraOrientation );
       
   479     __VTPRINTEXIT( "MH.GetCameraOrientations" )
       
   480     }
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 // CVtEngMediaHandler::RequestLastRemoteFrame
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 void CVtEngMediaHandler::RequestLastRemoteFrame( )
       
   487     {
       
   488     __VTPRINTENTER( "MH.RequestLastRemoteFrame" )    
       
   489     if( iRemoteVideo )
       
   490         iRemoteVideo->RequestLastFrame();    
       
   491     __VTPRINTEXIT( "MH.RequestLastRemoteFrame" )
       
   492     }
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CVtEngMediaHandler::ValidateCommand
       
   496 // Checks if command is valid in current proto state.
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 TInt CVtEngMediaHandler::ValidateCommand( const TVtEngCommandId aCommand ) const
       
   500     {
       
   501     __VTPRINTENTER( "MH.ValidateCommand" )
       
   502     __VTPRINT2( DEBUG_MEDIA, "MH.ValidateCommand cmd=%d", aCommand )
       
   503     TInt okToPerform( KErrNotReady );
       
   504     if ( iInitialized )
       
   505         {
       
   506         switch ( aCommand )
       
   507             {
       
   508             case KVtEngMuteOutgoingAudio:
       
   509             case KVtEngUnmuteOutgoingAudio:
       
   510                 // mute/unmute not possible if audio channel closed.
       
   511                 if ( IsFlag( EOutAudioChannelClosed ) ) {
       
   512                     break;
       
   513                 }
       
   514             case KVtEngSetAudioRouting:
       
   515             case KVtEngSetAudioVolume:
       
   516                 if ( ( iProtoState == MVtProtocolCommand::EConnected ) && !iPendingOp )
       
   517                     {
       
   518                     okToPerform = KErrNone;
       
   519                     }
       
   520                 break;            
       
   521             case KVtEngIncreaseAudioVolume:
       
   522             case KVtEngDecreaseAudioVolume:
       
   523 
       
   524                 if ( iProtoState == MVtProtocolCommand::EConnected )
       
   525                     {
       
   526                     okToPerform = KErrNone;
       
   527                     }
       
   528                 break;
       
   529             case KVtEngRequestLastRemoteFrame:            
       
   530                 if ( iProtoState == MVtProtocolCommand::EConnected )
       
   531                     {
       
   532                     okToPerform = KErrNone;
       
   533                     }
       
   534                 break;
       
   535             case KVtEngPrepareViewFinder:
       
   536             case KVtEngPrepareViewFinderDSA:
       
   537             case KVtEngPrepareRemoteRenderDSA:
       
   538             case KVtEngPrepareViewFinderDP:
       
   539             case KVtEngPrepareRemoteRenderDP:
       
   540             case KVtEngPrepareRemoteRenderNGA:
       
   541                 okToPerform = KErrNone; // can be done any time
       
   542                 break;
       
   543 
       
   544             case KVtEngHandleLayoutChange:
       
   545                 if ( iLocalVideo && iLocalVideo->ActiveProvider() !=
       
   546                         CVtEngLocalVideo::KVtEngProviderNone  && !iPendingOp )
       
   547                     {
       
   548                     okToPerform = KErrNone;
       
   549                     }
       
   550                 break;
       
   551 
       
   552             case KVtEngSetZoomStep:
       
   553                 {
       
   554                 const CVtEngLocalVideo::TVtEngProviderType
       
   555                     activeProvider( iLocalVideo->ActiveProvider() );
       
   556                 if ( iRequestStatus == NULL &&
       
   557                      iVSInitState == EInitStateNone &&
       
   558                      ( activeProvider == CVtEngLocalVideo::KVtEngProviderCam1 ||
       
   559                      activeProvider == CVtEngLocalVideo::KVtEngProviderCam2 ) )
       
   560                     {
       
   561                     okToPerform = KErrNone;
       
   562                     }
       
   563                 }
       
   564                 break;
       
   565             case KVtEngSetSource:
       
   566                 if ( !IsFlag( EOutVideoChannelClosed ) )
       
   567                     {
       
   568                     okToPerform = KErrNone;
       
   569                     }
       
   570                 // when EOutVideoChannelClosed is active
       
   571                 // don't allow source switch because it may require
       
   572                 // pause or resume on Protocol which would fail when video
       
   573                 // channel is closed.
       
   574                 // Note1: this is especially for the case when channel is
       
   575                 // closed after being already open.
       
   576                 // Note2: it must be possible to set source already before Protocol
       
   577                 // is connected (in MONA calls) so Proto state check is not done.
       
   578                  break;
       
   579             case KVtEngPrepareCamera:
       
   580             case KVtEngStartViewFinder:
       
   581             case KVtEngFreeze:
       
   582             case KVtEngUnfreeze:
       
   583                 if ( iRequestStatus == NULL &&
       
   584                      // If initialising or change provider during reset then
       
   585                      // not allowed
       
   586                      iVSInitState == EInitStateNone &&
       
   587                      // If terminate ongoing then not allowed
       
   588                      iProtoState != MVtProtocolCommand::EIdle )
       
   589                     {
       
   590                     okToPerform = KErrNone;
       
   591                     if( aCommand == KVtEngFreeze )
       
   592                         {
       
   593                         if( !iLocalVideo->OkToFreeze() )
       
   594                             {
       
   595                             okToPerform = KErrNotReady;
       
   596                             }
       
   597                         }
       
   598                     else if( aCommand == KVtEngUnfreeze )
       
   599                         {
       
   600                         if( !iLocalVideo->OkToUnfreeze() )
       
   601                             {
       
   602                             okToPerform = KErrNotReady;
       
   603                             }
       
   604                         }
       
   605                    }
       
   606                 break;
       
   607             case KVtEngSetVideoQuality:
       
   608                 if( IsPending( ESetVideoQuality ) != KErrNotFound )
       
   609                     {
       
   610                     okToPerform = KErrNotReady;
       
   611                     }
       
   612                 else
       
   613                     {
       
   614                     if ( iRequestStatus == NULL && iProtoState != MVtProtocolCommand::EIdle )
       
   615                         {
       
   616                         okToPerform = KErrNone;
       
   617                         }
       
   618                     }
       
   619                 break;
       
   620 
       
   621             case KVtEngInitializeShareImage:
       
   622                 {
       
   623                 TShareObjectState objectSharingState;
       
   624                 GetObjectSharingState( objectSharingState );
       
   625                 if ( ( objectSharingState != ENotAbleToShare ) &&
       
   626                     ( objectSharingState != EInitializingShareImage ) &&
       
   627                     !IsFlag( EOutVideoChannelClosed ) )
       
   628                     {
       
   629                     okToPerform = KErrNone;
       
   630                     }
       
   631                 }
       
   632                 break;
       
   633 
       
   634             case KVtEngStartShareImage:
       
   635                 {
       
   636                 TShareObjectState objectSharingState;
       
   637                 GetObjectSharingState( objectSharingState );
       
   638                 if( objectSharingState != ENotAbleToShare )
       
   639                     {
       
   640                     okToPerform = KErrNone;
       
   641                     }
       
   642                 }
       
   643                 break;
       
   644 
       
   645             case KVtEngStopShareImage:
       
   646                 {
       
   647                 TShareObjectState objectSharingState;
       
   648                 GetObjectSharingState( objectSharingState );
       
   649                 if ( ( objectSharingState == ESharingImage ) &&
       
   650                     !IsFlag( EOutVideoChannelClosed ) )
       
   651                     {
       
   652                     okToPerform = KErrNone;
       
   653                     }
       
   654                 }
       
   655                 break;
       
   656 
       
   657             case KVtEngTerminateSession:
       
   658                 if ( iProtoState == MVtProtocolCommand::EConnected ||
       
   659                      iProtoState == MVtProtocolCommand::EConnecting )
       
   660                     {
       
   661                     okToPerform = KErrNone;
       
   662                     }
       
   663                 break;
       
   664 
       
   665             default:
       
   666                 okToPerform= KErrNotSupported;
       
   667                 break;
       
   668             }
       
   669         }
       
   670     __VTPRINT2( DEBUG_MEDIA, "MH.ValidateCommand okToPerform=%d", okToPerform )
       
   671     __VTPRINTEXIT( "MH.ValidateCommand" )
       
   672     return okToPerform;
       
   673     }
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CVtEngMediaHandler::IsVideoChannelClosed
       
   677 // -----------------------------------------------------------------------------
       
   678 //
       
   679 TBool CVtEngMediaHandler::IsVideoChannelClosed() const
       
   680     {
       
   681     __VTPRINTENTER( "MH.IsVideoChannelClosed" )
       
   682     const TBool result( IsFlag( EOutVideoChannelClosed ) );
       
   683     __VTPRINTEXITR( "MH.IsVideoChannelClosed %d", result )
       
   684     return result;
       
   685     }
       
   686 
       
   687 // -----------------------------------------------------------------------------
       
   688 // CVtEngMediaHandler::HandleL
       
   689 // Handles a request.
       
   690 //
       
   691 // -----------------------------------------------------------------------------
       
   692 //
       
   693 void CVtEngMediaHandler::HandleL( CVtEngOperation& aOperation )
       
   694     {
       
   695     __VTPRINTENTER( "MH.HandleL" )
       
   696 
       
   697     const TVtEngCommandId id( aOperation.Command() );
       
   698     if ( !iInitialized )
       
   699         {
       
   700         __VTPRINT( DEBUG_MEDIA, "MH.Handle not ready" )
       
   701         User::Leave( KErrNotReady );
       
   702         }
       
   703     __VTPRINT2( DEBUG_MEDIA, "MH.Handle cmdId=%d", id )
       
   704     switch ( id )
       
   705         {
       
   706         case KVtEngSetUIForeground:
       
   707             TBool foregroundValue;
       
   708             TVtEngOpParamUtil<TBool>::Set( foregroundValue, aOperation );
       
   709             if( iLocalVideo )
       
   710                 {
       
   711                 iLocalVideo->SetUIForeground( foregroundValue );
       
   712                 }
       
   713             if( iRemoteVideo )
       
   714                 {
       
   715                 iRemoteVideo->SetUIForegroundL( foregroundValue );
       
   716                 }
       
   717             break;
       
   718 
       
   719         case KVtEngSetAudioVolume:
       
   720             {
       
   721             __VTPRINT( DEBUG_MEDIA, "MH.Handle.Vol" )
       
   722             MVtEngAudio::TVtEngOutputVolume volSetting;
       
   723             TVtEngOpParamUtil<MVtEngAudio::TVtEngOutputVolume>::Set(
       
   724                 volSetting, aOperation );
       
   725 
       
   726             // Store volume.
       
   727             CVtEngSettings& settings = CVtEngUtility::Settings();
       
   728             settings.SetVolume(
       
   729                 volSetting.iHandsetVolume,
       
   730                 volSetting.iHandsfreeVolume,
       
   731                 ETrue );
       
   732             settings.SetVolume(
       
   733                 volSetting.iHandsetVolume,
       
   734                 volSetting.iHandsfreeVolume,
       
   735                 EFalse );
       
   736 
       
   737             // Update volume.
       
   738             iPendingVolumeOp = &aOperation;
       
   739             AssignPendingOp( aOperation );
       
   740             UpdateVolume();
       
   741 
       
   742             if ( IsPending( ESetAudioVolume ) == KErrNotFound )
       
   743                 {
       
   744                 // No volume operation ongoing. Need to complete operation by itself.
       
   745                 AsyncCompleteOp();
       
   746                 }
       
   747             }
       
   748             break;
       
   749 
       
   750         case KVtEngIncreaseAudioVolume:
       
   751             {
       
   752             CVtEngAudioHandler& audioHandler(
       
   753                 static_cast< CVtEngAudioHandler& >(
       
   754                     CVtEngUtility::StateManager()->Handlers().Audio() ) );
       
   755             if ( audioHandler.IncreaseVolume() )
       
   756                 {
       
   757                 UpdateVolume();
       
   758                 }
       
   759             }
       
   760             break;
       
   761 
       
   762         case KVtEngDecreaseAudioVolume:
       
   763             {
       
   764             CVtEngAudioHandler& audioHandler(
       
   765                 static_cast< CVtEngAudioHandler& >(
       
   766                     CVtEngUtility::StateManager()->Handlers().Audio() ) );
       
   767             if ( audioHandler.DecreaseVolume() )
       
   768                 {
       
   769                 UpdateVolume();
       
   770                 }
       
   771             }
       
   772             break;
       
   773 
       
   774         case KVtEngMuteOutgoingAudio:
       
   775             {
       
   776             // No Local video if not on target
       
   777 #if !defined( __WINS__ )
       
   778             AddOperation( EMuteAudio,
       
   779                 iSessionCommand->PauseAudioL( *iLocalVideo->AudioSource()) );
       
   780 #endif // !WINS
       
   781             AssignPendingOp( aOperation );
       
   782             }
       
   783             break;
       
   784         case KVtEngUnmuteOutgoingAudio:
       
   785             {
       
   786             // No Local video if not on target
       
   787 #if !defined( __WINS__ )
       
   788             AddOperation ( EUnmuteAudio,
       
   789                 iSessionCommand->ResumeAudioL( *iLocalVideo->AudioSource() ) );
       
   790 #endif // !WINS
       
   791             AssignPendingOp( aOperation );
       
   792             }
       
   793             break;
       
   794         case KVtEngPrepareViewFinder:
       
   795             {
       
   796             const TPckgC<TVtEngRenderingOptions>& pckg =
       
   797                 static_cast< const TPckgC<TVtEngRenderingOptions>& >
       
   798                 ( *aOperation.Parameters() );
       
   799             const TVtEngRenderingOptions& options = pckg();
       
   800             iLocalVideo->SetViewFinderParameters( options );
       
   801             }
       
   802             break;
       
   803         case KVtEngPrepareRemoteRenderNGA:
       
   804             {
       
   805             const TPckgC<TVtEngRenderingOptionsNGA>& pckg =
       
   806                 static_cast< const TPckgC<TVtEngRenderingOptionsNGA>& >
       
   807                 ( *aOperation.Parameters() );
       
   808             const TVtEngRenderingOptionsNGA& options = pckg();
       
   809              iRemoteVideo->SetRenderingParametersL( options );     
       
   810             }
       
   811             break;
       
   812         case KVtEngPrepareViewFinderDSA:
       
   813         case KVtEngPrepareRemoteRenderDSA:
       
   814             {
       
   815             const TPckgC<TVtEngRenderingOptionsDSA>& pckg =
       
   816                 static_cast< const TPckgC<TVtEngRenderingOptionsDSA>& >
       
   817                 ( *aOperation.Parameters() );
       
   818             const TVtEngRenderingOptionsDSA& options = pckg();
       
   819             if ( id == KVtEngPrepareViewFinderDSA )
       
   820                 {
       
   821                 iLocalVideo->SetViewFinderParameters( options );
       
   822                 }
       
   823             else if ( iRemoteVideo )
       
   824                 {
       
   825                 iRemoteVideo->SetRenderingParametersL( options );
       
   826                 }
       
   827             }
       
   828             break;
       
   829 
       
   830         case KVtEngPrepareViewFinderDP:
       
   831         case KVtEngPrepareRemoteRenderDP:
       
   832             {
       
   833             const TPckgC<TVtEngRenderingOptionsDP>& pckg =
       
   834                 static_cast< const TPckgC<TVtEngRenderingOptionsDP>& >
       
   835                 ( *aOperation.Parameters() );
       
   836             const TVtEngRenderingOptionsDP& options = pckg();
       
   837             if ( id == KVtEngPrepareViewFinderDP )
       
   838                 {
       
   839                 iLocalVideo->SetViewFinderParameters( options );
       
   840                 }
       
   841             else if ( iRemoteVideo )
       
   842                 {
       
   843                 iRemoteVideo->SetRenderingParametersL( options );
       
   844                 }
       
   845             }
       
   846             break;
       
   847 
       
   848         case KVtEngHandleLayoutChange:
       
   849             iLocalVideo->HandleLayoutChangeL();
       
   850             AssignPendingOp( aOperation );
       
   851             break;
       
   852 
       
   853         case KVtEngSetSource:
       
   854             {
       
   855             __VTPRINT( DEBUG_MEDIA, "MH.set source" )
       
   856             MVtEngMedia::TMediaSource source;
       
   857             TVtEngOpParamUtil<MVtEngMedia::TMediaSource>::Set( source,
       
   858                 aOperation );
       
   859 
       
   860             iLocalVideo->InitializeOnly( EFalse );
       
   861             TOperation startedOp( ENone );
       
   862             switch ( source )
       
   863                 {
       
   864                 case EMediaCamera:
       
   865                     __VTPRINT( DEBUG_MEDIA, "EMediaCamera" )
       
   866                     iTempProviderInfo =
       
   867                     ( iSelectedCameraId == ESecondaryCamera ) ?
       
   868                         CVtEngLocalVideo::KVtEngProviderCam2 :
       
   869                         CVtEngLocalVideo::KVtEngProviderCam1;
       
   870 
       
   871                     SetFlag( EProtoContVideoBlankProv );
       
   872                     startedOp = EnableVideoL( ETrue );
       
   873                     if ( startedOp == ENone )
       
   874                         {
       
   875                         // Did nothing
       
   876                         ClearFlag( EProtoContVideoBlankProv );
       
   877                         }
       
   878                     iLocalVideo->ResumeVideoSending();
       
   879                     break;
       
   880                 case EMediaCameraPri:
       
   881                     __VTPRINT( DEBUG_MEDIA, "EMediaCameraPri" )
       
   882                     iTempProviderInfo = CVtEngLocalVideo::KVtEngProviderCam1;
       
   883                     iSelectedCameraId = EPrimaryCamera;
       
   884                     ClearFlag( EProtoContVideoBlankProv );
       
   885                     break;
       
   886                 case EMediaCameraSec:
       
   887                     __VTPRINT( DEBUG_MEDIA, "EMediaCameraSec" )
       
   888                     iTempProviderInfo = CVtEngLocalVideo::KVtEngProviderCam2;
       
   889                     iSelectedCameraId = ESecondaryCamera;
       
   890                     ClearFlag( EProtoContVideoBlankProv );
       
   891                     break;
       
   892                 case EMediaStillImage:
       
   893                     __VTPRINT( DEBUG_MEDIA, "EMediaStillImage" )
       
   894                     iTempProviderInfo = CVtEngLocalVideo::KVtEngProviderImage;
       
   895                     SetFlag( EProtoContVideoBlankProv );
       
   896                     startedOp = EnableVideoL( ETrue );
       
   897                     if ( startedOp == ENone )
       
   898                         {
       
   899                         // Did nothing
       
   900                         ClearFlag( EProtoContVideoBlankProv );
       
   901                         }
       
   902                     break;
       
   903                 case EMediaNone:
       
   904                     __VTPRINT( DEBUG_MEDIA | DEBUG_RETURN, "EMediaNone" )
       
   905                     if ( CVtEngUtility::Settings().
       
   906                     	 IsDefaultStillImageDefined() )
       
   907                         {
       
   908                         iTempProviderInfo =
       
   909                         CVtEngLocalVideo::KVtEngProviderDefaultStillImage;
       
   910 
       
   911                         SetFlag( EProtoContVideoBlankProv );
       
   912                         startedOp = EnableVideoL( ETrue );
       
   913                         if ( startedOp == ENone )
       
   914                             {
       
   915                             // Did nothing
       
   916                             ClearFlag( EProtoContVideoBlankProv );
       
   917                             }
       
   918                         }
       
   919                     else
       
   920                         {
       
   921                         iTempProviderInfo =
       
   922                         CVtEngLocalVideo::KVtEngProviderNone;
       
   923 
       
   924                         ClearFlag( EProtoContVideoBlankProv );
       
   925                         SetFlag( EProtoPauseVideoBlankProv );
       
   926                         if ( !IsFlag(
       
   927                             EProtoVideoSourceAdded ) && iProtoState != MVtProtocolCommand::EConnected )
       
   928                             {
       
   929                             // Set as not enabled video when no sources
       
   930                             __VTPRINT( DEBUG_MEDIA, "MH.set blanked - not ready" )
       
   931                             EnableVideoL( EFalse );
       
   932                             }
       
   933                         else
       
   934                             {
       
   935                             // we have "done" something
       
   936                             startedOp = EDisableVideo;
       
   937                             iLocalVideo->PauseVideoSending();
       
   938                             }
       
   939                         }
       
   940                     break;
       
   941                 default:
       
   942                     __VTPRINT( DEBUG_MEDIA, "invalid source" )
       
   943                     User::Leave( KErrArgument );
       
   944                 }
       
   945             TBool selectOngoing( EFalse );
       
   946             ClearFlag( ESourceUpdateNeeded );
       
   947             TInt err( KErrNone );
       
   948 
       
   949             // Either pausing or switching between still and camera
       
   950             if ( !IsFlag( EProtoContVideoBlankProv ) )
       
   951                 {
       
   952                 TRAP( err, selectOngoing =
       
   953                     iLocalVideo->SelectSourceL( iTempProviderInfo ) );
       
   954                 __VTPRINT3( DEBUG_MEDIA, "     ongoing=%d, op=%d",selectOngoing,
       
   955                     startedOp )
       
   956                 }
       
   957 
       
   958             if ( ( selectOngoing || IsFlag( EProtoContVideoBlankProv ) ||
       
   959                 IsFlag( EProtoContVideoBlankInit ) ) &&
       
   960                 startedOp != ENone && err == KErrNone )
       
   961                 {
       
   962                 // Enabling/disabling video started. Set flag that operation
       
   963                 // should be completed only when both callback from Protocol and
       
   964                 // local video (switch done) are complete.
       
   965                 __VTPRINT( DEBUG_MEDIA, "MH.set source 2stage" )
       
   966                 SetFlag( ETwoStageOperation );
       
   967                 }
       
   968             else
       
   969                 {
       
   970                 User::LeaveIfError( err );
       
   971                 }
       
   972             AssignPendingOp( aOperation );
       
   973             }
       
   974             break;
       
   975         case KVtEngPrepareCamera:
       
   976             {
       
   977             __VTPRINT( DEBUG_MEDIA, "MH.prepare cam" )
       
   978             MVtEngMedia::TPrepareCameraParams params;
       
   979             if ( aOperation.Parameters() )
       
   980                 {
       
   981                 TVtEngOpParamUtil< MVtEngMedia::TPrepareCameraParams >
       
   982                     ::Set( params, aOperation );
       
   983                 }
       
   984             else
       
   985                 {
       
   986                 params.iMediaSource = EMediaCamera;
       
   987                 params.iInitialize = ETrue;
       
   988                 }
       
   989             CVtEngLocalVideo::TVtEngProviderType
       
   990                 type( CVtEngLocalVideo::KVtEngProviderCam1 );
       
   991             switch ( params.iMediaSource )
       
   992                 {
       
   993                 case EMediaCamera:
       
   994                     type = ( iSelectedCameraId == ESecondaryCamera ) ?
       
   995                     CVtEngLocalVideo::KVtEngProviderCam2 :
       
   996                         CVtEngLocalVideo::KVtEngProviderCam1;
       
   997                     break;
       
   998                 case EMediaCameraPri:
       
   999                     iSelectedCameraId = EPrimaryCamera;
       
  1000                     type = CVtEngLocalVideo::KVtEngProviderCam1;
       
  1001                     break;
       
  1002                 case EMediaCameraSec:
       
  1003                     iSelectedCameraId = ESecondaryCamera;
       
  1004                     type = CVtEngLocalVideo::KVtEngProviderCam2;
       
  1005                     break;
       
  1006                 default:
       
  1007                     User::Leave( KErrArgument );
       
  1008                     break;
       
  1009                 }
       
  1010             iLocalVideo->SetIsPrepareCameraCalled( ETrue );
       
  1011             AssignPendingOp( aOperation );
       
  1012             if ( params.iInitialize )
       
  1013                 {
       
  1014                 __VTPRINT( DEBUG_MEDIA, "MH.prepare cam iInitialize TRUE" )
       
  1015                 iLocalVideo->InitializeOnly();
       
  1016                 ClearFlag( ESourceUpdateNeeded );
       
  1017                 iLocalVideo->SelectSourceL( type );
       
  1018                 }
       
  1019             else
       
  1020                 {
       
  1021                 __VTPRINT( DEBUG_MEDIA,
       
  1022                     "MH.prepare cam iInitialize FALSE, complete with KErrNone" )
       
  1023                 AsyncCompleteOp( KErrNone );
       
  1024                 }
       
  1025             }
       
  1026             break;
       
  1027 
       
  1028         case KVtEngSetZoomStep:
       
  1029             {
       
  1030             TInt zoom( 0 );
       
  1031             TVtEngOpParamUtil<TInt>::Set( zoom, aOperation );
       
  1032             iLocalVideo->SetDigitalZoomFactorL( zoom );
       
  1033             }
       
  1034             break;
       
  1035 
       
  1036         case KVtEngFreeze:
       
  1037             iLocalVideo->FreezeL();
       
  1038             break;
       
  1039 
       
  1040         case KVtEngUnfreeze:
       
  1041             iLocalVideo->UnfreezeL();
       
  1042             AssignPendingOp( aOperation );
       
  1043             break;
       
  1044 
       
  1045         case KVtEngStartViewFinder:
       
  1046             iLocalVideo->StartViewFinderL( ETrue );
       
  1047             break;
       
  1048         case KVtEngStopViewFinder:
       
  1049             iLocalVideo->StopViewFinder( ETrue );
       
  1050             break;
       
  1051         case KVtEngStartRenderRemote:
       
  1052             iRemoteVideo->StartVideoL();
       
  1053             break;
       
  1054         case KVtEngStopRenderRemote:
       
  1055             iRemoteVideo->StopVideoRendering();
       
  1056             break;
       
  1057         case KVtEngPauseRenderRemote:
       
  1058             iRemoteVideo->PauseVideoL();
       
  1059             break;
       
  1060         case KVtEngRequestLastRemoteFrame:
       
  1061             RequestLastRemoteFrame();
       
  1062             break;            
       
  1063         case KVtEngTerminateSession:
       
  1064             AssignPendingOp( aOperation );
       
  1065             break;
       
  1066 
       
  1067         // Set video quality
       
  1068         case KVtEngSetVideoQuality:
       
  1069             {
       
  1070             TVideoQuality videoQuality( EVideoQualityUndefined );
       
  1071             TVtEngOpParamUtil< TVideoQuality >::Set( videoQuality, aOperation );
       
  1072             SetPeerVideoQuality( videoQuality );
       
  1073             }
       
  1074             break;
       
  1075 
       
  1076         // Initialize share
       
  1077         case KVtEngInitializeShareImage:
       
  1078             {
       
  1079             TShareObjectImageParameters parameters;
       
  1080             TVtEngOpParamUtil< TShareObjectImageParameters >::Set(
       
  1081                 parameters, aOperation );
       
  1082             TBool firstTime = EFalse;
       
  1083             iLocalVideo->InitializeShareImageL( parameters, firstTime );
       
  1084             AssignPendingOp( aOperation );
       
  1085             if ( firstTime )
       
  1086                 {
       
  1087                 iVideoAction = IsFlag( EProtoVideoTrackPaused ) ?
       
  1088                     EVideoActionEnable : EVideoActionNone;
       
  1089                 }
       
  1090             }
       
  1091             break;
       
  1092 
       
  1093         // Start share
       
  1094         case KVtEngStartShareImage:
       
  1095             iLocalVideo->StartShareImageL();
       
  1096             AssignPendingOp( aOperation );
       
  1097             break;
       
  1098 
       
  1099         // Stop Image sharing
       
  1100         case KVtEngStopShareImage:
       
  1101             {
       
  1102             // If video sending needs to be paused when sharing is stopped
       
  1103             // then do it before doing the actual provider switch. It is
       
  1104             // done before hand to prevent dummy frame sending to receiving
       
  1105             // end (ie. black frame).
       
  1106             const TBool needsPause( iLocalVideo->ShareStoredSource() ==
       
  1107                 CVtEngLocalVideo::KVtEngProviderNone );
       
  1108             if ( needsPause )
       
  1109                 {
       
  1110                 // With this flag we prevent premature operation
       
  1111                 // complete after the pause command has been executed.
       
  1112                 iPauseNoCompleteOp = ETrue;
       
  1113                 EnableVideoL( EFalse );
       
  1114                 }
       
  1115             // reset the action flag.
       
  1116             iVideoAction = EVideoActionNone;
       
  1117             iLocalVideo->StopShareImageL();
       
  1118             AssignPendingOp( aOperation );
       
  1119             }
       
  1120             break;
       
  1121 
       
  1122         default:
       
  1123             User::Leave( KErrNotSupported );
       
  1124             break;
       
  1125         }
       
  1126     __VTPRINTEXIT( "MH.HandleL" )
       
  1127     }
       
  1128 
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // CVtEngMediaHandler::HandleSessionCommandEventL
       
  1132 // Handles command completion in protocol engine.
       
  1133 // -----------------------------------------------------------------------------
       
  1134 //
       
  1135 void CVtEngMediaHandler::HandleSessionCommandEventL(
       
  1136     const TVtCommandResponse& aResponse )
       
  1137     {
       
  1138     __VTPRINTENTER( "MH.HandleSessionCommandEventL" )
       
  1139     const TVtCommandType type( aResponse.iCmdType );
       
  1140     if ( type == EVtCommandGetSDKInfo )
       
  1141         {
       
  1142         // ignore completely
       
  1143         __VTPRINTEXIT( "MH.HandleSessionCommandEventL" )
       
  1144         return;
       
  1145         }
       
  1146     const TInt protoCmdId( aResponse.iCmdId );
       
  1147     const TInt protoResponse( aResponse.iCmdStatus );
       
  1148     TInt event( KVtEngEventNone );
       
  1149     __VTPRINT2( DEBUG_MEDIA, "MH.protoComC type=%d", type )
       
  1150     __VTPRINT3( DEBUG_MEDIA, "MH.protoComC cmdId=%d,response=%d", protoCmdId, protoResponse )
       
  1151 
       
  1152     CVtEngStateManager* states = CVtEngUtility::StateManager();
       
  1153     switch ( type )
       
  1154         {
       
  1155         case EVtCommandGetProtocolState:
       
  1156             break;
       
  1157         case EVtCommandInit://PVT_COMMAND_INIT -> ESetup
       
  1158             {
       
  1159             CVtEngUtility* utils = CVtEngUtility::EngineUtils();
       
  1160             iSessionCommand = utils->Initializer().GetSessionCommand();
       
  1161             iRemoteVideo = CVtEngRemoteVideo::NewL( *iSessionCommand, *states );
       
  1162             iInitialized = ETrue;
       
  1163             iProtoState = MVtProtocolCommand::ESetup;
       
  1164             __VTPRINT( DEBUG_MEDIA, "MH.protoComC: ESetup" )
       
  1165             states->Update();
       
  1166 
       
  1167 			// Get interfaces towards H324 and video encoder
       
  1168 			QueryProtoInterfacesL();
       
  1169             }
       
  1170             break;
       
  1171         case EVtCommandGetProtocolInterface:
       
  1172             {
       
  1173             __VTPRINT2( DEBUG_MEDIA, "MH.protoComC:IF response=%d", protoCmdId )
       
  1174             if ( protoResponse == KErrNone &&
       
  1175                  ( iProtoState == MVtProtocolCommand::ESetup ||
       
  1176 				   iProtoState == MVtProtocolCommand::EInitializing || // Allowed to query when initializing also
       
  1177                    iProtoState == MVtProtocolCommand::EConnecting ||
       
  1178                    iProtoState == MVtProtocolCommand::EConnected ) )
       
  1179                 {
       
  1180                 __ASSERT_DEBUG(
       
  1181                     IsPending( EGet324CtrlInterface ) != KErrNotFound
       
  1182                     || IsPending( EGetH263EncInterface ) != KErrNotFound,
       
  1183                     Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1184 
       
  1185                     //Check which interface.
       
  1186                 if ( MatchResponseToPendingOps(
       
  1187                     protoCmdId, EGet324CtrlInterface ) && iH324Config )
       
  1188                     {
       
  1189                     __VTPRINT( DEBUG_MEDIA, "MH.protoComC:324 IF" )
       
  1190                     iH324Config->SetObserverL ( this );
       
  1191 
       
  1192 					// Create DTMF handler with H324 interface.
       
  1193 					CVtEngUtility* utils = CVtEngUtility::EngineUtils();
       
  1194 					TRAP_IGNORE( utils->Initializer().CreateDtmfHandlerL( iH324Config ) );
       
  1195 
       
  1196                     // Set version to protocol -- cannot cause problem
       
  1197 #ifdef VTDEBUG
       
  1198                     TRAPD( err, SetVersionInfoL() );
       
  1199                     if ( err != KErrNone )
       
  1200                         {
       
  1201                         __VTPRINT2( DEBUG_MEDIA,
       
  1202                             "MH.protoComC:324 IF VersionInfo failed=%d", err )
       
  1203                         }
       
  1204 #else
       
  1205                     TRAP_IGNORE( SetVersionInfoL() );
       
  1206 #endif
       
  1207                     // Set resolutions to Proto.
       
  1208                     SetSupportedResolutions();
       
  1209 
       
  1210 					// Set Fast options
       
  1211 					SetFastCsupOptions();
       
  1212 
       
  1213                     SetFlag( EProto324IFAcquired );
       
  1214                     RemoveOperation( protoCmdId );
       
  1215                     states->Update();
       
  1216                     }
       
  1217                 else if ( MatchResponseToPendingOps(
       
  1218                     protoCmdId, EGetH263EncInterface ) )
       
  1219                     {
       
  1220                     __VTPRINT( DEBUG_MEDIA, "MH.protoComC:IF 263 created" )
       
  1221                     iH263Encoder->SetObserverL( this );
       
  1222                     RemoveOperation( protoCmdId );
       
  1223                     }
       
  1224                 else
       
  1225                     {
       
  1226                     // Not supported interface.
       
  1227                     __VTPRINT( DEBUG_MEDIA, "MH.protoComC:NOT requested" )
       
  1228                     }
       
  1229                 }
       
  1230             else
       
  1231                 {
       
  1232                 // failed or not in appropriate state
       
  1233                 __VTPRINT( DEBUG_MEDIA, "MH.protoComC:query IF fail/incorrect state" )
       
  1234                 RemoveOperation( protoCmdId );
       
  1235                 }
       
  1236             }
       
  1237             break;
       
  1238 
       
  1239         case EVtCommandResume:
       
  1240             {
       
  1241             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.protoComC Resume" )
       
  1242 
       
  1243             __ASSERT_DEBUG(
       
  1244                 IsPending( EUnmuteAudio ) != KErrNotFound ||
       
  1245                 IsPending( EEnableVideo ) != KErrNotFound ||
       
  1246                 IsPending( EEnableVideoInternal ) != KErrNotFound,
       
  1247                 Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1248 
       
  1249             // Was command unmute audio?
       
  1250             const TBool audioEnabled(
       
  1251                 MatchResponseToPendingOps( protoCmdId, EUnmuteAudio ) );
       
  1252 
       
  1253             if ( protoResponse == KErrNone )
       
  1254                 {
       
  1255                 if ( audioEnabled )
       
  1256                     {
       
  1257                     iLocalVideo->UnMute();
       
  1258                     event = KVtEngAudioUnmuted;
       
  1259                     }
       
  1260                 else
       
  1261                     {
       
  1262                     iLocalVideo->ResumeVideoSending();
       
  1263                     }
       
  1264                 }
       
  1265 
       
  1266             // Was command enable video?
       
  1267             const TBool videoEnabledByUser(
       
  1268                 MatchResponseToPendingOps( protoCmdId, EEnableVideo ) );
       
  1269 
       
  1270             RemoveOperation( protoCmdId );
       
  1271 
       
  1272             if ( videoEnabledByUser && IsFlag( ETwoStageOperation ) )
       
  1273                 {
       
  1274                 // Two-phase operation (resume + switch, resume completed)
       
  1275                 __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  1276                     "MH.video Resume 1st stage" )
       
  1277                 ClearFlag( ETwoStageOperation );
       
  1278                 ClearFlag( ESourceUpdateNeeded );
       
  1279                 iLocalVideo->SelectSourceL( iTempProviderInfo );
       
  1280                 iTempProviderInfo = CVtEngLocalVideo::KVtEngProviderNone;
       
  1281                 }
       
  1282             else if ( videoEnabledByUser || audioEnabled )
       
  1283                 {
       
  1284                 __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.video Resume " )
       
  1285                 CompleteOp( protoResponse );
       
  1286                 }
       
  1287 
       
  1288             // Do send an intra message
       
  1289             if ( IsFlag( EProtoVideoTrackPaused ) )
       
  1290                 {
       
  1291                 ClearFlag( EProtoVideoTrackPaused );
       
  1292                 if ( IsFlag( EProtoSendIntraFrame ) )
       
  1293                     {
       
  1294                     RequestFrame();
       
  1295                     }
       
  1296                 }
       
  1297             }
       
  1298             break;
       
  1299         case EVtCommandPause: // Audio or video disable
       
  1300             {
       
  1301             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.protoComC Pause" )
       
  1302             __ASSERT_DEBUG( iRequestStatus ||
       
  1303                 // uninit ongoing, still possible
       
  1304                 // to receive callback from protocol
       
  1305                 ( IsPending( EMuteAudio )    != KErrNotFound ||
       
  1306                 IsPending( EDisableVideo ) != KErrNotFound ),
       
  1307                 Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1308 
       
  1309             TBool videoDisabled( EFalse );
       
  1310 
       
  1311             // was command disable audio?
       
  1312             if ( MatchResponseToPendingOps( protoCmdId, EMuteAudio ) )
       
  1313                 {
       
  1314                 iLocalVideo->Mute();
       
  1315                 event = KVtEngAudioMuted;
       
  1316                 }
       
  1317             else
       
  1318                 {
       
  1319                 // was command disable video?
       
  1320                 videoDisabled = MatchResponseToPendingOps(
       
  1321                     protoCmdId, EDisableVideo );
       
  1322                 if ( videoDisabled )
       
  1323                     {
       
  1324                     SetFlag( EProtoVideoTrackPaused );
       
  1325                     }
       
  1326                 }
       
  1327             RemoveOperation( protoCmdId );
       
  1328             if ( IsFlag( ETwoStageOperation ) && videoDisabled )
       
  1329                 {
       
  1330                 __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  1331                     "MH.video pause 1st stage" )
       
  1332                 // First event out of two that DisableVideo video
       
  1333                 // is complete (waiting for event from local video).
       
  1334 
       
  1335                 if ( !IsPending( EEnableVideo ) )
       
  1336                     {
       
  1337                     ClearFlag( ETwoStageOperation );
       
  1338                     }
       
  1339                 else
       
  1340                     {
       
  1341                     // Except if pause was not user originated, i.e
       
  1342                     // pause done in the beginning because there is no
       
  1343                     // still image to be sent in MT call and video is paused
       
  1344                     // (user has not yet allowed video sending).
       
  1345                     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  1346                     "MH.video paused, 2stage NOT CLEARED" )
       
  1347                     }
       
  1348                 }
       
  1349             else
       
  1350                 {
       
  1351                 if ( !iPauseNoCompleteOp )
       
  1352                     {
       
  1353                     CompleteOp( protoResponse );
       
  1354                     }
       
  1355                 else
       
  1356                     {
       
  1357                     iPauseNoCompleteOp = EFalse;
       
  1358                     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  1359                         "MH.video paused due to share stop, clearing flag" )
       
  1360                     }
       
  1361                 }
       
  1362             }
       
  1363             break;
       
  1364         case EVtCommandAddDataSink:
       
  1365             {
       
  1366 			__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSink");
       
  1367             if ( protoResponse == KErrNone )
       
  1368                 {
       
  1369                 __ASSERT_DEBUG( iRequestStatus ||
       
  1370                     // uninit ongoing, still possible
       
  1371                     // to receive callback from pv2way
       
  1372                     ( IsPending( EAddVideoSink ) != KErrNotFound ||
       
  1373                     IsPending( EAddAudioSink ) != KErrNotFound ),
       
  1374                     Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1375 
       
  1376                 __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.data sink added" )
       
  1377 
       
  1378                 if ( MatchResponseToPendingOps( protoCmdId, EAddVideoSink )
       
  1379                         && ( iRemoteMediaState & EMediaVideoPreparing ) )
       
  1380                     {
       
  1381                     // Video sink added
       
  1382                     SetFlag( EProtoVideoSinkAdded );
       
  1383                     iRemoteMediaState &= ~EMediaVideoPreparing;
       
  1384                     iRemoteMediaState |= EMediaVideo;
       
  1385 					__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSink for VIDEO OK.");
       
  1386                     }
       
  1387                 else if ( MatchResponseToPendingOps( protoCmdId, EAddAudioSink )
       
  1388                             && ( iRemoteMediaState & EMediaAudioPreparing ) )
       
  1389                     {
       
  1390                     // Audio sink added
       
  1391                     SetFlag( EProtoAudioSinkAdded );
       
  1392                     iRemoteMediaState &= ~EMediaAudioPreparing;
       
  1393                     iRemoteMediaState |= EMediaAudio;
       
  1394 					__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSink for AUDIO OK.");
       
  1395                     // DevSound created in Proto => temporary devSound needed
       
  1396                     // for making audio routing work can be released now.
       
  1397                     CVtEngStateManager* stateManager =
       
  1398                         CVtEngUtility::StateManager();
       
  1399                     CVtEngAudioHandler& audioHandler =
       
  1400                         static_cast< CVtEngAudioHandler& >(
       
  1401                             stateManager->Handlers().Audio() );
       
  1402                     audioHandler.SetRoutingEnablerL( EFalse );
       
  1403                     RequestAudioControllerL();
       
  1404                     }
       
  1405                 else
       
  1406                     {
       
  1407                     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.protoComC invalid" )
       
  1408                     Panic( EVtEngPanicMediaHandlerOpStateFailure );
       
  1409                     }
       
  1410                 }
       
  1411 			else
       
  1412 				{
       
  1413 				__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSink FAILED");
       
  1414 
       
  1415 				if ( MatchResponseToPendingOps( protoCmdId, EAddVideoSink ) )
       
  1416 					{
       
  1417 					__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSink FAILED, INCOMING VIDEO");
       
  1418 
       
  1419 					iVideoIncomingLogicalChannel.iSameTypeClosingPending = EFalse;
       
  1420 					if( iVideoIncomingLogicalChannel.iSameTypeChannelReadyToOpen )
       
  1421 						{
       
  1422 						iVideoIncomingLogicalChannel.iSameTypeChannelReadyToOpen = EFalse;
       
  1423 
       
  1424 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE delayed adding VIDEO, ADDing SINK" )
       
  1425 						AddVideoSink( iVideoIncomingLogicalChannel.iLogicalChannelId );
       
  1426 						}
       
  1427 					}
       
  1428 				else
       
  1429 					{
       
  1430 					__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSink FAILED, INCOMING AUDIO");
       
  1431 
       
  1432 					iAudioIncomingLogicalChannel.iSameTypeClosingPending = EFalse;
       
  1433 					if( iAudioIncomingLogicalChannel.iSameTypeChannelReadyToOpen )
       
  1434 						{
       
  1435 						iAudioIncomingLogicalChannel.iSameTypeChannelReadyToOpen = EFalse;
       
  1436 
       
  1437 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE delayed adding AUDIO, ADDing SINK" )
       
  1438 						AddAudioSink( iAudioIncomingLogicalChannel.iLogicalChannelId );
       
  1439 						}
       
  1440 					}
       
  1441 				}
       
  1442             RemoveOperation( protoCmdId );
       
  1443             }
       
  1444             break;
       
  1445         case EVtCommandAddDataSource:
       
  1446             {
       
  1447             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.data source added" )
       
  1448 			__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSource");
       
  1449             if ( protoResponse == KErrNone &&
       
  1450                  ( iProtoState == MVtProtocolCommand::EConnected || iProtoState == MVtProtocolCommand::EConnecting || iProtoState == MVtProtocolCommand::ESetup ) )
       
  1451                 {
       
  1452                 if ( MatchResponseToPendingOps( protoCmdId, EAddVideoSource ) )
       
  1453                     {
       
  1454                     SetFlag( EProtoVideoSourceAdded );
       
  1455 
       
  1456                     // This flag was set if channel closed indication
       
  1457                     // EVtIndicationClosingTrack was received from Proto.
       
  1458                     ClearFlag( EOutVideoChannelClosed );
       
  1459 
       
  1460                     iLocalVideo->VideoChannelOpenedL();
       
  1461 
       
  1462                     CVtEngEventManager::NotifyEvent(
       
  1463                         KVtEngMediaOutgoingVideoChannelStatusChanged );
       
  1464 
       
  1465 					__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSource for VIDEO OK.");
       
  1466 
       
  1467 					// Adjust to normal value after Connect has completed
       
  1468 					// so MONA is over.
       
  1469 					if( iProtoState == MVtProtocolCommand::EConnected )
       
  1470 						{
       
  1471 						__VTPRINT( DEBUG_MEDIA, "LCN: Adjusting I Frame Interval in " )
       
  1472 						__VTPRINT( DEBUG_MEDIA, "LCN: ADD_DATA_SOURCE for Video, Connect has completed earlier." )
       
  1473 						__VTPRINT( DEBUG_MEDIA, "LCN: Normal I-frame rate." )
       
  1474 
       
  1475 
       
  1476 						// Setting I-Frame interval to normal since MONA connections are over.
       
  1477 						AddOperation( ESetIFrameInterval,
       
  1478 						    // I-Frame every 10 second.
       
  1479 						    iH263Encoder->SetIntraFrameInterval( 100 ) );
       
  1480 						}
       
  1481 					else if( iProtoState == MVtProtocolCommand::EConnecting || iProtoState == MVtProtocolCommand::ESetup )
       
  1482 						{
       
  1483 						__VTPRINT( DEBUG_MEDIA, "LCN: Adjusting I Frame Interval in " )
       
  1484 						__VTPRINT( DEBUG_MEDIA, "LCN: ADD_DATA_SOURCE for Video, Proto state Connecting." )
       
  1485 						__VTPRINT( DEBUG_MEDIA, "LCN: High I-frame rate" )
       
  1486 
       
  1487 						// MONA negotiations ongoing, I-Frame invertal must be small
       
  1488 						AddOperation( ESetIFrameInterval,
       
  1489 						    // 10 I-Frames every 1 second.
       
  1490 						    iH263Encoder->SetIntraFrameInterval( 10000 ) );
       
  1491 						}
       
  1492 
       
  1493                     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  1494                         "MH.data setting default videoquality" )
       
  1495 
       
  1496                     // Set default frame rate and send indication to peer
       
  1497                     if ( !IsFlag( EVideoQualitySetByPeer ) )
       
  1498                         {
       
  1499                         SetVideoQualityL( EVideoQualityNormal, EFalse );
       
  1500                         }
       
  1501 
       
  1502                     __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  1503                         "MH.data source added check flag" )
       
  1504                     if ( IsFlag( EProtoPauseVideoRequested ) )
       
  1505                         {
       
  1506                         __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  1507                             "MH.data source added pausing video" )
       
  1508                         EnableVideoL( EFalse );
       
  1509                         }
       
  1510                     }
       
  1511                 else if ( MatchResponseToPendingOps(
       
  1512                     protoCmdId, EAddAudioSource ) )
       
  1513                     {
       
  1514                     SetFlag( EProtoAudioSourceAdded );
       
  1515 
       
  1516                     // This flag was set if channel closed indication
       
  1517                     // EVtIndicationClosingTrack was received from PV.
       
  1518                     ClearFlag( EOutAudioChannelClosed );
       
  1519 
       
  1520                     CVtEngEventManager::NotifyEvent(
       
  1521                         KVtEngMediaOutgoingAudioChannelStatusChanged );
       
  1522 
       
  1523 					__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSource for AUDIO OK.");
       
  1524                     }
       
  1525                 }
       
  1526 
       
  1527 			else
       
  1528 				{
       
  1529 				__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSource FAILED");
       
  1530 
       
  1531 				if ( MatchResponseToPendingOps( protoCmdId, EAddVideoSource ) )
       
  1532 					{
       
  1533 					__VTPRINT( DEBUG_MEDIA, "EVtCommandAddDataSource FAILED, OUTGOING VIDEO");
       
  1534 
       
  1535 					iVideoOutgoingLogicalChannel.iSameTypeClosingPending = EFalse;
       
  1536 					if( iVideoOutgoingLogicalChannel.iSameTypeChannelReadyToOpen )
       
  1537 						{
       
  1538 						iVideoOutgoingLogicalChannel.iSameTypeChannelReadyToOpen = EFalse;
       
  1539 
       
  1540 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE delayed adding VIDEO, ADDing SOURCE" )
       
  1541 						AddVideoSource( iVideoOutgoingLogicalChannel.iLogicalChannelId );
       
  1542 						}
       
  1543 					}
       
  1544 				else
       
  1545 					{
       
  1546 					__VTPRINT( DEBUG_MEDIA, "LCN: EVtCommandAddDataSource FAILED, OUTGOING AUDIO");
       
  1547 
       
  1548 					iAudioOutgoingLogicalChannel.iSameTypeClosingPending = EFalse;
       
  1549 					if( iAudioOutgoingLogicalChannel.iSameTypeChannelReadyToOpen )
       
  1550 						{
       
  1551 						iAudioOutgoingLogicalChannel.iSameTypeChannelReadyToOpen = EFalse;
       
  1552 
       
  1553 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE delayed adding AUDIO, ADDing SOURCE" )
       
  1554 						AddAudioSource( iAudioOutgoingLogicalChannel.iLogicalChannelId );
       
  1555 						}
       
  1556 					}
       
  1557 				}
       
  1558 
       
  1559             if ( !RemoveOperation( protoCmdId ) )
       
  1560                 {
       
  1561                 __ASSERT_DEBUG( iRequestStatus != NULL,
       
  1562                 // uninit ongoing, still possible to receive
       
  1563                 // callback from protocol
       
  1564                 Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1565                 }
       
  1566             states->Update();
       
  1567             break;
       
  1568             }
       
  1569 
       
  1570         case EVtCommandConnect:
       
  1571             {
       
  1572             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.Connect complete" )
       
  1573             if ( protoResponse == KErrNone )
       
  1574                 {
       
  1575                 __ASSERT_DEBUG( IsPending( EConnectProto ) != KErrNotFound,
       
  1576                     Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1577                 RemoveOperation( EConnectProto );
       
  1578                 iProtoState = MVtProtocolCommand::EConnected;
       
  1579                 __VTPRINT( DEBUG_MEDIA, "MH.protoComC: EConnected" )
       
  1580                 states->Update();
       
  1581 
       
  1582 				// Adjust only if VideoSource adding has compled
       
  1583 				if( IsPending( EAddVideoSource ) == KErrNotFound )
       
  1584 					{
       
  1585 					__VTPRINT( DEBUG_MEDIA, "LCN: Adjusting I FrameInterval " )
       
  1586 					__VTPRINT( DEBUG_MEDIA, "LCN: after Connect has completed" )
       
  1587 					__VTPRINT( DEBUG_MEDIA, "LCN: Normal I-frame interval." )
       
  1588 
       
  1589 
       
  1590 					// Setting I-Frame interval to normal since MONA connections are over.
       
  1591 					AddOperation( ESetIFrameInterval,
       
  1592 					    // I-Frame every 10 second.
       
  1593 					    iH263Encoder->SetIntraFrameInterval( 100 ) );
       
  1594 					}
       
  1595                 }
       
  1596             else
       
  1597                 {
       
  1598                 if ( iProtoState == MVtProtocolCommand::EConnecting ) {
       
  1599                     // it is possible that we're here because call was hanged up
       
  1600                     iProtoState = MVtProtocolCommand::ESetup;
       
  1601                     }
       
  1602                 RemoveOperation( EConnectProto );
       
  1603                 // connect may have failed due to disconnect request (possible only in debug env?)
       
  1604                 if ( iPendingOp &&
       
  1605                    ( iPendingOp->Command() == KVtEngTerminateSession ) )
       
  1606                     {
       
  1607                     __VTPRINT( DEBUG_MEDIA,
       
  1608                         "complete KVtEngTerminateSession on connect failure" )
       
  1609                     CompleteOp( KErrNone );                        
       
  1610                     }
       
  1611                 else
       
  1612                     {
       
  1613                     __VTPRINT( DEBUG_MEDIA,
       
  1614                         "request fallback on connect failure" )
       
  1615                     // request fallback from telephony
       
  1616                     CVtEngUtility* utils = CVtEngUtility::EngineUtils();
       
  1617                     utils->MediatorCommands().VoiceFallback();                    
       
  1618                     }
       
  1619                 states->Update();
       
  1620                 }
       
  1621             }
       
  1622             break;
       
  1623         case EVtCommandRemoveDataSource:
       
  1624         case EVtCommandRemoveDataSink:
       
  1625             break;
       
  1626         case EVtCommandReset:
       
  1627             {
       
  1628             __ASSERT_DEBUG( IsPending( EDestructProtoPhaseReset ) != KErrNotFound,
       
  1629                 Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1630             __VTPRINT( DEBUG_MEDIA, "MH.protoComC:RESET complete" )
       
  1631             RemoveOperation( protoCmdId );
       
  1632             if ( protoResponse == KErrNone )
       
  1633                 {
       
  1634                 iProtoState = MVtProtocolCommand::EIdle;
       
  1635                 __VTPRINT( DEBUG_MEDIA, "MH.protoComC: EIdle" )
       
  1636                 }
       
  1637             if ( iRequestStatus )
       
  1638                 {
       
  1639                 // we're in uninitialization process
       
  1640                 // do this even if reset failed!
       
  1641                 iLocalVideo->StopViewFinder();
       
  1642                 UninitializeNextStep();
       
  1643                 }
       
  1644             states->Update();
       
  1645             }
       
  1646             break;
       
  1647 		case EVtCommandDeleteProtocolInterface:
       
  1648 			{
       
  1649 
       
  1650 			// Remove pending operation from list
       
  1651 			RemoveOperation( protoCmdId );
       
  1652 
       
  1653 			// Proceed to disconnecting if inetrfaces are free'd
       
  1654 			UninitializeNextStep();
       
  1655             states->Update();
       
  1656 
       
  1657 			break;
       
  1658 			}
       
  1659         case EVtCommandDisconnect:
       
  1660             {
       
  1661             __ASSERT_DEBUG(
       
  1662                 IsPending( EDestructProtoPhaseDisconnect ) != KErrNotFound ||
       
  1663                 IsPending( ETerminateSession ) != KErrNotFound,
       
  1664                 Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1665             __VTPRINT( DEBUG_MEDIA, "MH.protoComC:DISCONNECT complete" )
       
  1666             if ( protoResponse == KErrNone )
       
  1667                 {
       
  1668                 iProtoState = MVtProtocolCommand::ESetup;
       
  1669                 __VTPRINT( DEBUG_MEDIA, "MH.protoComC: ESetup_disconnect" )
       
  1670                 }
       
  1671 
       
  1672             delete iTimer;
       
  1673             iTimer = NULL;
       
  1674 
       
  1675             RemoveOperation( protoCmdId );
       
  1676 
       
  1677             // If disconnect was requested while connecting we
       
  1678             // have connect operation added.
       
  1679             RemoveOperation( EConnectProto );
       
  1680 
       
  1681             if ( iRequestStatus )
       
  1682                 {
       
  1683                 // continue uninitialization
       
  1684                 UninitializeNextStep();
       
  1685                 }
       
  1686             else
       
  1687                 {
       
  1688                 // complete plain disconnect request from  UI
       
  1689                 CompleteOp( protoResponse );
       
  1690                 }
       
  1691             states->Update();
       
  1692             }
       
  1693             break;
       
  1694         case EVtCommandCancelAllCommands:
       
  1695             {
       
  1696             __ASSERT_DEBUG(
       
  1697                 IsPending( EUninitializeCancelAllProto ) != KErrNotFound,
       
  1698                 Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  1699             RemoveOperation( protoCmdId );
       
  1700 
       
  1701             UninitializeNextStep();
       
  1702             }
       
  1703             break;
       
  1704         default:
       
  1705             {
       
  1706             __VTPRINT( DEBUG_MEDIA, "MH.protoComC Unknown Proto reply" )
       
  1707             }
       
  1708             break;
       
  1709         }
       
  1710     if ( event != KVtEngEventNone )
       
  1711         {
       
  1712         CVtEngEventManager::NotifyEvent( event );
       
  1713         }
       
  1714     __VTPRINTEXIT( "MH.HandleSessionCommandEventL" )
       
  1715     }
       
  1716 
       
  1717 // -----------------------------------------------------------------------------
       
  1718 // CVtEngMediaHandler::HandleSessionInformationalEventL
       
  1719 // Handles event from protocol engine.
       
  1720 // -----------------------------------------------------------------------------
       
  1721 //
       
  1722 void CVtEngMediaHandler::HandleSessionInformationalEventL(
       
  1723     const TVtIndicationEvent& aEvent)
       
  1724     {
       
  1725     __VTPRINTENTER( "MH.InfoEvent" )
       
  1726     const TInt type( aEvent.iEventType );
       
  1727     __VTPRINT2( DEBUG_MEDIA, "MH.protoHIE type=%d", type )
       
  1728 
       
  1729     TVtIndicationEvent& event =
       
  1730         const_cast<TVtIndicationEvent&>(aEvent);
       
  1731     const TUint8* buffer = event.iLocalBuffer;
       
  1732 
       
  1733     if ( buffer || type == EVtIndicationDisconnect )
       
  1734         {
       
  1735         TBool video( EFalse );
       
  1736         TBool audio( EFalse );
       
  1737         __VTPRINT( DEBUG_MEDIA, "MH.protoHIE inbound")
       
  1738         if ( type != EVtIndicationDisconnect &&
       
  1739             type != EVtIndicationUserInputCapability )
       
  1740             {
       
  1741             switch ( buffer[0] )
       
  1742                 {
       
  1743                 case EVtAudio:
       
  1744                     audio = ETrue;
       
  1745                     break;
       
  1746                 case EVtVideo:
       
  1747                     video = ETrue;
       
  1748                     break;
       
  1749                 case EVtControl:
       
  1750                 case EVtData:
       
  1751                 case EVtMediaNone:
       
  1752                     __VTPRINTEXIT( "MH.InfoEvent" )
       
  1753                     return;
       
  1754 
       
  1755                 default:
       
  1756                     break;
       
  1757 
       
  1758                 }
       
  1759             }
       
  1760 
       
  1761          __VTPRINT( DEBUG_MEDIA, "MH.protoHIE acting according" )
       
  1762         TInt event( KVtEngEventNone );
       
  1763         switch ( type )
       
  1764             {
       
  1765             case EVtIndicationIncomingTrack:
       
  1766                 {
       
  1767                 __VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE EVtIndicationIncomingTrack" )
       
  1768                 if ( video )
       
  1769                     {
       
  1770 					TInt tempID = *((TInt*)(buffer+4));
       
  1771 					__VTPRINT2( DEBUG_MEDIA, "LCN: MH.protoHIE INCOMING VIDEO:%d", tempID )
       
  1772 
       
  1773 					if( !iVideoIncomingLogicalChannel.iSameTypeClosingPending )
       
  1774 						{
       
  1775 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE InTrack VIDEO, ADDing SINK" )
       
  1776 						AddVideoSink( tempID );
       
  1777 						}
       
  1778 					else
       
  1779 						{
       
  1780 						// Store old value since ID will change when we get outgoing track indication
       
  1781 						iVideoIncomingLogicalChannel.iLogicalChannelIdClosing = iVideoIncomingLogicalChannel.iLogicalChannelId;
       
  1782 						iVideoIncomingLogicalChannel.iSameTypeChannelReadyToOpen = ETrue;
       
  1783 						}
       
  1784 
       
  1785 					// Store new LCN ID.
       
  1786 					iVideoIncomingLogicalChannel.iLogicalChannelId = tempID;
       
  1787                     }
       
  1788                 else if ( audio )
       
  1789                     {
       
  1790 					TInt tempID = *((TInt*)(buffer+4));
       
  1791 					__VTPRINT2( DEBUG_MEDIA, "LCN: MH.protoHIE INCOMING AUDIO:%d", tempID )
       
  1792 
       
  1793 					if( !iAudioIncomingLogicalChannel.iSameTypeClosingPending )
       
  1794 						{
       
  1795 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE InTrack AUDIO, ADDing SINK" )
       
  1796 						AddAudioSink( tempID );
       
  1797 						}
       
  1798 					else
       
  1799 						{
       
  1800 						// Store old value since ID will change when we get outgoing track indication
       
  1801 						iAudioIncomingLogicalChannel.iLogicalChannelIdClosing = iAudioIncomingLogicalChannel.iLogicalChannelId;
       
  1802 						iAudioIncomingLogicalChannel.iSameTypeChannelReadyToOpen = ETrue;
       
  1803 						}
       
  1804 
       
  1805 					// Store new LCN ID.
       
  1806 					iAudioIncomingLogicalChannel.iLogicalChannelId = tempID;
       
  1807 					}
       
  1808 				}
       
  1809                 break;
       
  1810 
       
  1811 			case EVtIndicationOutgoingTrack:
       
  1812                 {
       
  1813                 __VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE EVtIndicationOutgoingTrack" )
       
  1814                 if ( video )
       
  1815                     {
       
  1816 					TInt tempID = *((TInt*)(buffer+4));
       
  1817 					__VTPRINT2( DEBUG_MEDIA, "LCN: MH.protoHIE OUTGOING VIDEO ID:%d", tempID )
       
  1818 
       
  1819 					if( !iVideoOutgoingLogicalChannel.iSameTypeClosingPending )
       
  1820 						{
       
  1821 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE OutTrack VIDEO, ADDing SOURCE" )
       
  1822 						AddVideoSource( tempID );
       
  1823 						}
       
  1824 					else
       
  1825 						{
       
  1826 						// Store old value since ID will change when we get outgoing track indication
       
  1827 						iVideoOutgoingLogicalChannel.iLogicalChannelIdClosing = iVideoOutgoingLogicalChannel.iLogicalChannelId;
       
  1828 						iVideoOutgoingLogicalChannel.iSameTypeChannelReadyToOpen = ETrue;
       
  1829 						}
       
  1830 
       
  1831 					// Store new LCN ID.
       
  1832 					iVideoOutgoingLogicalChannel.iLogicalChannelId = tempID;
       
  1833 					}
       
  1834                 else if ( audio )
       
  1835                     {
       
  1836 
       
  1837 					TInt tempID = *((TInt*)(buffer+4));
       
  1838 					__VTPRINT2( DEBUG_MEDIA, "LCN: MH.protoHIE OUTGOING AUDIO:%d", tempID )
       
  1839 
       
  1840 					if( !iAudioOutgoingLogicalChannel.iSameTypeClosingPending )
       
  1841 						{
       
  1842 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE OutTrack AUDIO, ADDing SOURCE" )
       
  1843 						AddAudioSource( tempID );
       
  1844 						}
       
  1845 					else
       
  1846 						{
       
  1847 						// Store old value since ID will change when we get outgoing track indication
       
  1848 						iAudioOutgoingLogicalChannel.iLogicalChannelIdClosing = iAudioOutgoingLogicalChannel.iLogicalChannelId;
       
  1849 						iAudioOutgoingLogicalChannel.iSameTypeChannelReadyToOpen = ETrue;
       
  1850 						}
       
  1851 
       
  1852 					// Store new LCN ID.
       
  1853 					iAudioOutgoingLogicalChannel.iLogicalChannelId = tempID;
       
  1854                     }
       
  1855                 }
       
  1856                 break;
       
  1857 
       
  1858 			case EVtIndicationClosingTrack:
       
  1859 				{
       
  1860 			
       
  1861 				TUint8 direction = buffer[0];
       
  1862 				TInt tempID = *((TInt*)(buffer+4));
       
  1863 
       
  1864 				__VTPRINT3( DEBUG_MEDIA, "LCN: MH.protoHIE PEVtIndicationClosingTrack ID:%d, dir:%d", tempID, direction )
       
  1865 
       
  1866 				if( direction == EVtIncoming )
       
  1867 					{
       
  1868 					if( tempID == iVideoIncomingLogicalChannel.iLogicalChannelId )
       
  1869 						{
       
  1870 						iVideoIncomingLogicalChannel.iSameTypeClosingPending = ETrue;
       
  1871 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE CLOSING INCOMING VIDEO" )
       
  1872 						}
       
  1873 					else
       
  1874 						{
       
  1875 						iAudioIncomingLogicalChannel.iSameTypeClosingPending = ETrue;
       
  1876 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE CLOSING INCOMING AUDIO" )
       
  1877 						}
       
  1878 					}
       
  1879 				else
       
  1880 					{
       
  1881                     TInt uiEvent;
       
  1882 					if( tempID == iVideoOutgoingLogicalChannel.iLogicalChannelId )
       
  1883 						{
       
  1884 						SetFlag( EOutVideoChannelClosed );
       
  1885 						iVideoOutgoingLogicalChannel.iSameTypeClosingPending = ETrue;
       
  1886 						uiEvent = KVtEngMediaOutgoingVideoChannelStatusChanged;
       
  1887 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE CLOSING OUTGOING VIDEO" )
       
  1888 						}
       
  1889 					else
       
  1890 						{
       
  1891 						SetFlag( EOutAudioChannelClosed );
       
  1892 						iAudioOutgoingLogicalChannel.iSameTypeClosingPending = ETrue;
       
  1893 						uiEvent = KVtEngMediaOutgoingAudioChannelStatusChanged;
       
  1894 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE CLOSING OUTGOING AUDIO" )
       
  1895 						}
       
  1896                     CVtEngEventManager::NotifyEvent( uiEvent );
       
  1897 					}
       
  1898 				}
       
  1899 				break;
       
  1900 
       
  1901             case EVtIndicationCloseTrack:
       
  1902 				{
       
  1903 
       
  1904 				TInt tempID = *((TInt*)(buffer+4));
       
  1905 			
       
  1906 				TUint8 direction = buffer[0];
       
  1907 
       
  1908 				__VTPRINT3( DEBUG_MEDIA, "LCN: MH.protoHIE EVtIndicationCloseTrack ID:%d, dir:%d", tempID, direction )
       
  1909 
       
  1910 				if( direction == EVtIncoming )
       
  1911 					{
       
  1912 					if( iVideoIncomingLogicalChannel.iLogicalChannelId == tempID ||
       
  1913 						( iVideoIncomingLogicalChannel.iSameTypeClosingPending &&
       
  1914 						  tempID == iVideoIncomingLogicalChannel.iLogicalChannelIdClosing )
       
  1915 						)
       
  1916 						{
       
  1917 						iVideoIncomingLogicalChannel.iSameTypeClosingPending = EFalse;
       
  1918                         iRemoteMediaState &= ~EMediaVideo;
       
  1919 
       
  1920 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE CLOSE INCOMING VIDEO" )
       
  1921 
       
  1922 						if( iVideoIncomingLogicalChannel.iSameTypeChannelReadyToOpen )
       
  1923 							{
       
  1924 							iVideoIncomingLogicalChannel.iSameTypeChannelReadyToOpen = EFalse;
       
  1925 
       
  1926 							__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE delayed adding VIDEO, ADDing SINK" )
       
  1927 							AddVideoSink( iVideoIncomingLogicalChannel.iLogicalChannelId );
       
  1928 							}
       
  1929 						}
       
  1930 					else
       
  1931 						{
       
  1932 						iAudioIncomingLogicalChannel.iSameTypeClosingPending = EFalse;
       
  1933 
       
  1934 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE CLOSE INCOMING AUDIO" )
       
  1935 
       
  1936 						if( iAudioIncomingLogicalChannel.iSameTypeChannelReadyToOpen )
       
  1937 							{
       
  1938 							iAudioIncomingLogicalChannel.iSameTypeChannelReadyToOpen = EFalse;
       
  1939 
       
  1940 							__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE delayed adding AUDIO, ADDing SINK" )
       
  1941 							AddAudioSink( iAudioIncomingLogicalChannel.iLogicalChannelId );
       
  1942 							}
       
  1943 						}
       
  1944 					}
       
  1945 				else
       
  1946 					{
       
  1947 					if( iVideoOutgoingLogicalChannel.iLogicalChannelId == tempID ||
       
  1948 						( iVideoOutgoingLogicalChannel.iSameTypeClosingPending &&
       
  1949 						  tempID == iVideoOutgoingLogicalChannel.iLogicalChannelIdClosing )
       
  1950 						)
       
  1951 						{
       
  1952 						iVideoOutgoingLogicalChannel.iSameTypeClosingPending = EFalse;
       
  1953 
       
  1954 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE CLOSE OUTGOING VIDEO" )
       
  1955 
       
  1956 						if( iVideoOutgoingLogicalChannel.iSameTypeChannelReadyToOpen )
       
  1957 							{
       
  1958 							iVideoOutgoingLogicalChannel.iSameTypeChannelReadyToOpen = EFalse;
       
  1959 
       
  1960 							__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE delayed adding VIDEO, ADDing SOURCE" )
       
  1961 							AddVideoSource( iVideoOutgoingLogicalChannel.iLogicalChannelId );
       
  1962 							}
       
  1963 						}
       
  1964 					else
       
  1965 						{
       
  1966 						iAudioOutgoingLogicalChannel.iSameTypeClosingPending = EFalse;
       
  1967 
       
  1968 						__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE CLOSE OUTGOING AUDIO" )
       
  1969 
       
  1970 						if( iAudioOutgoingLogicalChannel.iSameTypeChannelReadyToOpen )
       
  1971 							{
       
  1972 							iAudioOutgoingLogicalChannel.iSameTypeChannelReadyToOpen = EFalse;
       
  1973 
       
  1974 							__VTPRINT( DEBUG_MEDIA, "LCN: MH.protoHIE delayed adding AUDIO, ADDing SOURCE" )
       
  1975 							AddAudioSource( iAudioOutgoingLogicalChannel.iLogicalChannelId );
       
  1976 							}
       
  1977 						}
       
  1978 					}
       
  1979 				}
       
  1980                 break;
       
  1981             case EVtIndicationResumeTrack:
       
  1982                 __VTPRINT2( DEBUG_MEDIA, "MH.protoHIE X is resumed %d", buffer[1] )
       
  1983                 if ( buffer[1] == EVtIncoming ) // Only for remote
       
  1984                     {
       
  1985                     if ( video )
       
  1986                         {
       
  1987                         __VTPRINT( DEBUG_MEDIA, "MH.protoHIE video resumed" )
       
  1988                         event = KVtEngRemoteVideoResumed;
       
  1989                         ClearFlag( EProtoVideoTrackPaused );
       
  1990                         }
       
  1991                     else if ( audio )
       
  1992                         {
       
  1993                         __VTPRINT( DEBUG_MEDIA, "MH.protoHIE audio resumed" )
       
  1994                         event = KVtEngRemoteAudioResumed;
       
  1995                         ClearFlag( EProtoAudioTrackPaused );
       
  1996                         }
       
  1997                     }
       
  1998                 break;
       
  1999             case EVtIndicationPauseTrack:
       
  2000                 __VTPRINT2( DEBUG_MEDIA, "MH.protoHIE X is paused %d", buffer[1] )
       
  2001                 if ( buffer[1] == EVtIncoming ) // Only for remote
       
  2002                     {
       
  2003                     if ( audio )
       
  2004                         {
       
  2005                         __VTPRINT( DEBUG_MEDIA, "MH.protoHIE audio paused" )
       
  2006                         SetFlag( EProtoAudioTrackPaused );
       
  2007                         event = KVtEngRemoteAudioPaused;
       
  2008                         }
       
  2009                     else if ( video )
       
  2010                         {
       
  2011                         __VTPRINT( DEBUG_MEDIA, "MH.protoHIE video paused" )
       
  2012                         SetFlag( EProtoVideoTrackPaused );
       
  2013                         event = KVtEngRemoteVideoPaused;
       
  2014                         }
       
  2015                     }
       
  2016                 break;
       
  2017             case EVtIndicationDisconnect:
       
  2018                 {
       
  2019                 __VTPRINT( DEBUG_MEDIA | DEBUG_RETURN, "MH.protoHIE PID" )
       
  2020 
       
  2021                 // Fix for disconnecting remote (bearer). Engine
       
  2022                 // needs to send KVtEngRemoteDisconnect event to UI to notify
       
  2023                 // UI that call can not be hangup!
       
  2024                 CVtEngEventManager::NotifyEvent( KVtEngRemoteDisconnect );
       
  2025 
       
  2026                 delete iTimer;
       
  2027                 iTimer = NULL;
       
  2028                 CVtEngStateManager* states = CVtEngUtility::StateManager();
       
  2029                 iProtoState = MVtProtocolCommand::ESetup;
       
  2030                 __VTPRINT( DEBUG_MEDIA, "MH.protoComC: ESetup_indi_disconnect" )
       
  2031                 states->Update();
       
  2032                 if ( iPendingOp &&
       
  2033                      ( iPendingOp->Command() == KVtEngTerminateSession  ||
       
  2034                        iPendingOp->Command() == KVtEngResetEngine ) )
       
  2035                     {
       
  2036                     __VTPRINT2( DEBUG_MEDIA, "MH.protoHIE PID PO", iPendingOp->Command() )
       
  2037                     // Complete only KVtEngTerminateSession, if KVtEngResetEngine
       
  2038                     // is pending complete it after uninitialisation is finalised.
       
  2039                     if ( iPendingOp->Command() == KVtEngTerminateSession )
       
  2040                         {
       
  2041                         CompleteOp( KErrNone );
       
  2042                         }
       
  2043                     }
       
  2044                 else
       
  2045                     {
       
  2046                     __VTPRINT( DEBUG_MEDIA | DEBUG_RETURN, "MH.protoHIE PID RO")
       
  2047                     UninitializeNextStep();
       
  2048                     }
       
  2049                 }
       
  2050                 break;
       
  2051             default:
       
  2052                 break;
       
  2053             }
       
  2054         if ( KVtEngEventNone != event )
       
  2055             {
       
  2056             CVtEngEventManager::NotifyEvent( event );
       
  2057             }
       
  2058         }
       
  2059     __VTPRINTEXIT( "MH.InfoEvent" )
       
  2060     }
       
  2061 
       
  2062 // -----------------------------------------------------------------------------
       
  2063 // CVtEngMediaHandler::HandleSessionErrorEventL
       
  2064 // Handles error event from protocol engine.
       
  2065 // -----------------------------------------------------------------------------
       
  2066 //
       
  2067 #ifdef VTDEBUG
       
  2068 void CVtEngMediaHandler::HandleSessionErrorEventL( const TVtErrorEvent& aEvent )
       
  2069 #else
       
  2070 void CVtEngMediaHandler::
       
  2071     HandleSessionErrorEventL( const TVtErrorEvent& /* aEvent */ )
       
  2072 #endif // VTDEBUG
       
  2073     {
       
  2074     // Must have an implementation.
       
  2075     __VTPRINT2( DEBUG_MEDIA, "MH.protoHEE,%d", aEvent.iEventType )
       
  2076     }
       
  2077 
       
  2078 // -----------------------------------------------------------------------------
       
  2079 // CVtEngMediaHandler::HandleSettingChangedL
       
  2080 // Handles still image setting change.
       
  2081 // -----------------------------------------------------------------------------
       
  2082 //
       
  2083 void CVtEngMediaHandler::HandleSettingChangedL(
       
  2084     CVtEngSettings::TSettingId aId,
       
  2085     const TDesC& /*aValue*/ )
       
  2086     {
       
  2087     __VTPRINTENTER( "MH.HandleSettingChangedL" )
       
  2088     if ( aId == CVtEngSettings::ESelectVolume ||
       
  2089          aId == CVtEngSettings::EHandsetVolume ||
       
  2090          aId == CVtEngSettings::EHandsfreeVolume )
       
  2091         {
       
  2092         __VTPRINT2( DEBUG_MEDIA, "MH.volChgd %d", aId )
       
  2093         UpdateVolume();
       
  2094 
       
  2095         if ( aId == CVtEngSettings::EHandsetVolume ||
       
  2096              aId == CVtEngSettings::EHandsfreeVolume )
       
  2097             {
       
  2098             CVtEngEventManager::NotifyEvent(
       
  2099                 KVtEngAudioOutputVolumeChanged );
       
  2100             }
       
  2101         }
       
  2102     else if ( aId == CVtEngSettings::EStillImage ||
       
  2103               aId == CVtEngSettings::EStillImagePath )
       
  2104         {
       
  2105         __VTPRINT( DEBUG_MEDIA, "MH.stillChgd" )
       
  2106 
       
  2107         TShareObjectState shareState;
       
  2108         GetObjectSharingState( shareState );
       
  2109         if ( shareState == EInitializingShareImage ||
       
  2110              shareState == ESharingImage )
       
  2111             {
       
  2112             iLocalVideo->SettingsChanged();
       
  2113             return;
       
  2114             }
       
  2115 
       
  2116         CVtEngSettings& settings = CVtEngUtility::Settings();
       
  2117         const CVtEngSettings::TVtEngVideoCallConfig& config =
       
  2118             settings.Config();
       
  2119 
       
  2120         const CVtEngLocalVideo::TVtEngProviderType
       
  2121             activeProvider( iLocalVideo->ActiveProvider() );
       
  2122         if ( config.iVideo.iImageIsValid )
       
  2123             {
       
  2124             __VTPRINT( DEBUG_GEN, "MH.HSC valid" )
       
  2125             EnableVideoL( ETrue );
       
  2126             // if still image is not active we should only
       
  2127             // initialize it, not start after initialization.
       
  2128             const TBool initOnly( activeProvider ==
       
  2129                 CVtEngLocalVideo::KVtEngProviderCam1 ||
       
  2130                 activeProvider == CVtEngLocalVideo::KVtEngProviderCam2 ||
       
  2131                 activeProvider ==
       
  2132                 CVtEngLocalVideo::KVtEngProviderShareImage );
       
  2133             iLocalVideo->InitializeOnlyEx( initOnly );
       
  2134             TRAPD( err,iLocalVideo->SetStillImageL( !initOnly ) );
       
  2135             if ( err == KErrNotReady )
       
  2136                 {
       
  2137                 __VTPRINT( DEBUG_GEN, "MH.HSC waiting...")
       
  2138                 // Another switch ongoing, wait until it is done.
       
  2139                 }
       
  2140             }
       
  2141         else
       
  2142             {
       
  2143             __VTPRINT( DEBUG_GEN, "MH.HSC invalid" )
       
  2144 			__VTPRINT2( DEBUG_MEDIA, "MH.HSC provider=", activeProvider )
       
  2145 		    if ( CVtEngUtility::Settings().IsDefaultStillImageDefined() )
       
  2146                 {
       
  2147                 __VTPRINT( DEBUG_MEDIA, "MH.SetDefaultStillImageL" )
       
  2148                 if ( activeProvider == CVtEngLocalVideo::KVtEngProviderImage )
       
  2149                     {
       
  2150                     iLocalVideo->SetDefaultStillImageL();
       
  2151                     }
       
  2152                 }
       
  2153             else
       
  2154                 {
       
  2155                 if( activeProvider !=
       
  2156                     CVtEngLocalVideo::KVtEngProviderCam1 &&
       
  2157                     activeProvider != CVtEngLocalVideo::KVtEngProviderCam2 )
       
  2158 				    {
       
  2159 				    EnableVideoL( EFalse );
       
  2160 				    }
       
  2161                     __VTPRINT( DEBUG_MEDIA, "MH.tStillImageL" )
       
  2162                 iLocalVideo->SetStillImageL( ETrue );
       
  2163                 }
       
  2164 
       
  2165             }
       
  2166         }
       
  2167     else
       
  2168         {
       
  2169         // Do nothing, but satisfy lint.
       
  2170         __VTPRINT2( DEBUG_MEDIA, "MH.HSC not handled=%d", aId )
       
  2171         }
       
  2172     __VTPRINTEXIT( "MH.HSC" )
       
  2173     }
       
  2174 
       
  2175 // -----------------------------------------------------------------------------
       
  2176 // CVtEngMediaHandler::InitializeL
       
  2177 // Initializes settings listeners.
       
  2178 // Sets still image and initializes default provider.
       
  2179 // -----------------------------------------------------------------------------
       
  2180 //
       
  2181 void CVtEngMediaHandler::InitializeL( TRequestStatus& aStatus )
       
  2182     {
       
  2183     __VTPRINTENTER( "MH.InitializeL" )
       
  2184     // configure still image
       
  2185     CVtEngSettings& settings = CVtEngUtility::Settings();
       
  2186     settings.NotifyChangeL( CVtEngSettings::EStillImage, *this );
       
  2187     settings.NotifyChangeL( CVtEngSettings::EStillImagePath, *this );
       
  2188     settings.NotifyChangeL( CVtEngSettings::ESelectVolume, *this );
       
  2189     settings.NotifyChangeL( CVtEngSettings::EHandsetVolume, *this );
       
  2190     settings.NotifyChangeL( CVtEngSettings::EHandsfreeVolume, *this );
       
  2191 
       
  2192     const CVtEngSettings::TVtEngVideoCallConfig& config = settings.Config();
       
  2193     TInt err( KErrNotFound );
       
  2194     if ( config.iVideo.iImageIsValid )
       
  2195         {
       
  2196         // first step initialize still, when that is complete, initialize blank
       
  2197         TRAP( err, iLocalVideo->SetStillImageL( ETrue ) );
       
  2198         if ( err == KErrNone )
       
  2199             {
       
  2200             iVSInitState = EStateInitStillImage;
       
  2201             iRequestStatus = &aStatus;
       
  2202             }
       
  2203         }
       
  2204     if ( err != KErrNone )
       
  2205         {
       
  2206         // Still provider init failed -> initialize blank
       
  2207         InitializeProviderL( aStatus );
       
  2208         }
       
  2209     __VTPRINTEXIT( "MH.InitializeL" )
       
  2210     }
       
  2211 
       
  2212 // -----------------------------------------------------------------------------
       
  2213 // CVtEngMediaHandler::CancelInitialize
       
  2214 // Sets initialization state as cancelled.
       
  2215 // -----------------------------------------------------------------------------
       
  2216 //
       
  2217 void CVtEngMediaHandler::CancelInitialize()
       
  2218     {
       
  2219     __VTPRINTENTER( "MH.CancelInitialize" )
       
  2220     iVSInitState = EStateInitCanceled;
       
  2221     __VTPRINTEXIT( "MH.CancelInitialize" )
       
  2222     }
       
  2223 
       
  2224 // -----------------------------------------------------------------------------
       
  2225 // CVtEngMediaHandler::InitializeProviderL
       
  2226 // Initializes default blank provider.
       
  2227 // -----------------------------------------------------------------------------
       
  2228 //
       
  2229 void CVtEngMediaHandler::InitializeProviderL( TRequestStatus& aStatus )
       
  2230     {
       
  2231     __VTPRINTENTER( "MH.InitializeProviderL" )
       
  2232     iLocalVideo->InitializeL();
       
  2233     iVSInitState = EStateInitProvider;
       
  2234     iRequestStatus = &aStatus;
       
  2235     __VTPRINTEXIT( "MH.InitializeProviderL" )
       
  2236     }
       
  2237 
       
  2238 // -----------------------------------------------------------------------------
       
  2239 // CVtEngMediaHandler::Uninitialize
       
  2240 // Frees all resources.
       
  2241 // -----------------------------------------------------------------------------
       
  2242 //
       
  2243 void CVtEngMediaHandler::Uninitialize( TRequestStatus& aStatus )
       
  2244     {
       
  2245     __VTPRINTENTER( "MH.Uninitialize" )
       
  2246     ClearFlag( ETwoStageOperation );
       
  2247     ClearFlag( ESourceUpdateNeeded );
       
  2248     iRequestStatus = &aStatus;
       
  2249     if ( iProtoState == MVtProtocolCommand::EDisconnecting )
       
  2250         {
       
  2251         // Protocol is disconnecting if
       
  2252         // 1) bearer was lost (and videoteleng issued disconnect on protocol), or
       
  2253         // 2) protocol issued disconnect due unrecoverable error or disconnect
       
  2254         //    request from remote terminal.
       
  2255         // And now UI requested 'reset engine' while performing disconnect.
       
  2256         // When disconnecting is complete check if iRequestStatus
       
  2257         // is not null AND iInitialized is ETrue.
       
  2258         // If so, Uninitialize has been called (UI requested reset).
       
  2259 
       
  2260         StopRendering();
       
  2261         __VTPRINT( DEBUG_MEDIA, "MH.UnInit wait for disconnect to complete" )
       
  2262         __VTPRINTEXIT( "MH.Uninitialize" )
       
  2263         return;
       
  2264         }
       
  2265     iInitialized = EFalse;
       
  2266     UninitializeNextStep();
       
  2267     __VTPRINTEXIT( "MH.Uninitialize" )
       
  2268     }
       
  2269 
       
  2270 // -----------------------------------------------------------------------------
       
  2271 // CVtEngMediaHandler::UninitializeNextStep
       
  2272 // Goes to next step in uninitialization
       
  2273 // -----------------------------------------------------------------------------
       
  2274 //
       
  2275 void CVtEngMediaHandler::UninitializeNextStep( )
       
  2276     {
       
  2277      __VTPRINTENTER( "MH.UninitializeNextStep" )
       
  2278     StopRendering();
       
  2279 
       
  2280     TOperation op( ENone );
       
  2281 
       
  2282     // CancelAllProtoCommands is no op if nothing to cancel or already pending.
       
  2283     // However, then op is still assigned with EUninitializeCancelAllProto to
       
  2284     // indicate it is pending and we must wait for it to complete.
       
  2285     CancelAllProtoCommands( op );
       
  2286 
       
  2287     if ( op == ENone ) // Cancellation is not pending
       
  2288         {
       
  2289         __VTPRINT2( DEBUG_MEDIA, "next step protostate=%d", iProtoState )
       
  2290         switch ( iProtoState )
       
  2291             {
       
  2292             case MVtProtocolCommand::EConnected:
       
  2293             case MVtProtocolCommand::EConnecting:
       
  2294                 op = EDestructProtoPhaseDisconnect;
       
  2295                 break;
       
  2296             case MVtProtocolCommand::ESetup:
       
  2297             // In EInitializing state operation is waited to complete. See
       
  2298             // CVtEngInitializer::ContinueOrRetry op==EReset and iStep==EInitProto
       
  2299 
       
  2300                 if( iH324Config || iH263Encoder )
       
  2301                     {
       
  2302                     // First remove interfaces, after completion perform reset
       
  2303                     op = ERemove324CtrlInterface;
       
  2304                     break;
       
  2305                     }
       
  2306 
       
  2307                 // If interfaces are already released or not even reserved, go to Reset.
       
  2308                 op = EDestructProtoPhaseReset;
       
  2309                 break;
       
  2310             case MVtProtocolCommand::EResetting:
       
  2311                 // Reset ongoing, wait for it to complete
       
  2312                 __VTPRINT( DEBUG_MEDIA, "MH.UnInit resetting" )
       
  2313                 break;
       
  2314             case MVtProtocolCommand::EIdle:
       
  2315                 op = ERemove324CtrlInterface;
       
  2316                 __VTPRINT( DEBUG_MEDIA, "MH.UnInit idling" )
       
  2317                 break;
       
  2318             default:
       
  2319                 __VTPRINT( DEBUG_MEDIA, "MH.UnInit invalid state" )
       
  2320                 break;
       
  2321             }
       
  2322         if ( op != ENone )
       
  2323             {
       
  2324             TRAPD( err, ContinueUninitializeL( op ) );
       
  2325             if ( err != KErrNone )
       
  2326                 {
       
  2327                 if ( iRequestStatus )
       
  2328                     {
       
  2329                     User::RequestComplete( iRequestStatus, err );
       
  2330                     iRequestStatus = NULL;
       
  2331                     }
       
  2332                 else
       
  2333                     {
       
  2334                     // Infinite waiting for end state!
       
  2335                     __VTPRINT( DEBUG_MEDIA, "MH. dead end!" )
       
  2336                     Panic( EVtEngPanicDisconnectTimerExpired );
       
  2337                     }
       
  2338                 __VTPRINT2( DEBUG_MEDIA, "next step err=%d", err )
       
  2339                 }
       
  2340             }
       
  2341         }
       
  2342     __VTPRINTEXIT( "MH.UninitializeNextStep" )
       
  2343     }
       
  2344 
       
  2345 // -----------------------------------------------------------------------------
       
  2346 // CVtEngMediaHandler::ContinueUninitializeL
       
  2347 // Completes uninitialization:
       
  2348 //   does disconnecting, deletes members.
       
  2349 // -----------------------------------------------------------------------------
       
  2350 //
       
  2351 void CVtEngMediaHandler::ContinueUninitializeL(
       
  2352     const TOperation aOp )
       
  2353     {
       
  2354     __VTPRINTENTER( "MH.ContinueUninitializeL" )
       
  2355     __VTPRINT2( DEBUG_MEDIA, "MH.ContUn op=%d", aOp)
       
  2356     switch ( aOp )
       
  2357         {
       
  2358         case EDestructProtoPhaseDisconnect: // causes DisconnectL on protocol
       
  2359 			__VTPRINT2( DEBUG_MEDIA, "MH.ContUn EDestructProtoPhaseDisconnect iProtoState=%d", iProtoState )
       
  2360 
       
  2361 			// Disconnecting only allowed in Connecting and Connected state.
       
  2362 			if( iProtoState == MVtProtocolCommand::EConnecting || iProtoState == MVtProtocolCommand::EConnected )
       
  2363 				{
       
  2364 				DisconnectProtoL();
       
  2365 				if ( iProtoState == MVtProtocolCommand::EDisconnecting ) {
       
  2366 					// started succefully disconnecting
       
  2367 					break;
       
  2368 					}
       
  2369 				}
       
  2370          // fall through if state was not proper was disconnect
       
  2371         case EDestructProtoPhaseReset:      // causes ResetL on protocol
       
  2372 
       
  2373             ResetProto2WayL();
       
  2374             if ( iProtoState == MVtProtocolCommand::EResetting )
       
  2375                 {
       
  2376                 break;
       
  2377                 }
       
  2378         // fall through if state was not proper for reset
       
  2379         case ERemove324CtrlInterface:
       
  2380             {
       
  2381             __VTPRINT( DEBUG_MEDIA, "MH.ContUn ERemove324CtrlInterface" )
       
  2382             const TBool extCmdPending( ExtensionCommandsPending() );
       
  2383             if ( !extCmdPending && ( iH324Config || iH263Encoder ) )
       
  2384                 { // no pending extension commands, interfaces can be released
       
  2385                   // this is no-op if already released
       
  2386 			    ReleaseProtoInterfacesL();
       
  2387                 break;
       
  2388 			    }
       
  2389 			if( extCmdPending ||
       
  2390 			    IsPending( ERemove324CtrlInterface ) != KErrNotFound ||
       
  2391 				IsPending( ERemoveH263EncInterface ) != KErrNotFound )
       
  2392 				{
       
  2393 				// Interface releasing has not completed yet, need to wait
       
  2394 				// until proceeding ahead.
       
  2395 				break;
       
  2396 				}
       
  2397             }
       
  2398         // fall through if interfaces are released
       
  2399         case EDestructSwitchBlank:
       
  2400             {
       
  2401             __VTPRINT( DEBUG_MEDIA, "MH.ContUn EDestructSwitchBlank" )
       
  2402             // provider must be selected to something else that
       
  2403             // is not deleted
       
  2404             const CVtEngLocalVideo::TVtEngProviderType
       
  2405                 activeProvider( iLocalVideo->ActiveProvider() );
       
  2406             if ( activeProvider != CVtEngLocalVideo::KVtEngProviderNone )
       
  2407                 {
       
  2408                 iLocalVideo->SelectSourceL( CVtEngLocalVideo::KVtEngProviderNone );
       
  2409                 iVSInitState = EStateWaitingProviderChangeForUninit;
       
  2410                 break;
       
  2411                 }
       
  2412             // blank provider already active so continue
       
  2413             iVSInitState = EInitStateNone;
       
  2414             }
       
  2415             // fall thru
       
  2416         case EDestructInternals:
       
  2417             __VTPRINT( DEBUG_MEDIA, "MH.ContUn EDestructInternals" )
       
  2418             iLocalVideo->Reset();
       
  2419             delete iRemoteVideo;
       
  2420             iRemoteVideo = NULL;
       
  2421             if ( iRequestStatus )
       
  2422                 {
       
  2423                 User::RequestComplete( iRequestStatus, KErrNone );
       
  2424                 iRequestStatus = NULL;
       
  2425                 }
       
  2426             break;
       
  2427         default:
       
  2428             // Should not happen
       
  2429             Panic( EVtEngPanicUnInitIncorrectOperation );
       
  2430             break;
       
  2431         }
       
  2432 
       
  2433     __VTPRINTEXIT( "MH.ContinueUninitializeL" )
       
  2434     }
       
  2435 
       
  2436 // -----------------------------------------------------------------------------
       
  2437 // CVtEngMediaHandler::StopRendering
       
  2438 // Stops all rendering.
       
  2439 // -----------------------------------------------------------------------------
       
  2440 //
       
  2441 void CVtEngMediaHandler::StopRendering()
       
  2442     {
       
  2443     __VTPRINTENTER( "MH.StopRendering" )
       
  2444     if ( iLocalVideo )
       
  2445         {
       
  2446         iLocalVideo->StopViewFinder();
       
  2447         }
       
  2448     if ( iRemoteVideo )
       
  2449         {
       
  2450         iRemoteVideo->StopVideoRendering();
       
  2451         }
       
  2452     __VTPRINTEXIT( "MH.StopRendering" )
       
  2453     }
       
  2454 
       
  2455 // -----------------------------------------------------------------------------
       
  2456 // CVtEngMediaHandler::UpdateVolume
       
  2457 // Updates volume values.
       
  2458 // -----------------------------------------------------------------------------
       
  2459 //
       
  2460 void CVtEngMediaHandler::UpdateVolume()
       
  2461     {
       
  2462     __VTPRINTENTER( "MH.UpdateVolume" )
       
  2463     if ( iUpdateVolumeAllowed && IsPending( ESetAudioVolume ) == KErrNotFound )
       
  2464         {
       
  2465         CVtEngSettings& settings = CVtEngUtility::Settings();
       
  2466 
       
  2467         TInt volume( 0 );
       
  2468         TInt err( settings.GetVolume( volume,
       
  2469             settings.CurrentVolume(), ETrue ) );
       
  2470         if ( err != KErrNone )
       
  2471             {
       
  2472             volume = settings.MinVolume();
       
  2473             }
       
  2474 
       
  2475         SetVolume( volume );
       
  2476         }
       
  2477     else
       
  2478         {
       
  2479         iUpdateVolumeRequired = ETrue;
       
  2480         }
       
  2481     __VTPRINTEXIT( "MH.UpdateVolume" )
       
  2482     }
       
  2483 
       
  2484 // -----------------------------------------------------------------------------
       
  2485 // CVtEngMediaHandler::AutoEnableVideo
       
  2486 // Enables video when primary camera becomes available while blank provider
       
  2487 // is active (i.e. video is disabled). This should not be called in other
       
  2488 // occations. Difference to EnableVideoL is that callback doesn't try to
       
  2489 // complete pending request to UI (that usually is different request than this).
       
  2490 // -----------------------------------------------------------------------------
       
  2491 //
       
  2492 TInt CVtEngMediaHandler::AutoEnableVideo( TBool aEnable )
       
  2493     {
       
  2494     __VTPRINTENTER( "MH.AutoEnableVideo" )
       
  2495     __VTPRINT( DEBUG_MEDIA, "MH.AutoEnableVideo" )
       
  2496     TOperation op( EDisableVideoInternal );
       
  2497     if ( aEnable )
       
  2498         {
       
  2499         op = EEnableVideoInternal;
       
  2500         }
       
  2501     TRAPD( err, EnableVideoL( aEnable, op ) );
       
  2502     __VTPRINTEXITR( "MH.AutoEnableVideo %d", err )
       
  2503     return err;
       
  2504     }
       
  2505 
       
  2506 // -----------------------------------------------------------------------------
       
  2507 // CVtEngMediaHandler::FinalizeUninitialization
       
  2508 // Deletes protocol.
       
  2509 // -----------------------------------------------------------------------------
       
  2510 //
       
  2511 void CVtEngMediaHandler::FinalizeUninitialization()
       
  2512     {
       
  2513     __VTPRINTENTER( "MH.FinalUninit" )
       
  2514     if ( iSessionCommand )
       
  2515         {
       
  2516         iAudioCtrl = NULL;
       
  2517         TInt err( KErrNone );
       
  2518 
       
  2519         // Delete the config interface
       
  2520         TRAP( err,
       
  2521             {
       
  2522 			if ( iSessionCommand )
       
  2523 				{
       
  2524 				VTProtocolFactory::DeleteSessionCommand( iSessionCommand );
       
  2525 				iSessionCommand = NULL;
       
  2526 				}
       
  2527 
       
  2528 			// Trapped to log the possible error
       
  2529             __VTPRINT( DEBUG_MEDIA, "MH.Deleted Terminal" )
       
  2530             } );
       
  2531         __VTPRINT2( DEBUG_MEDIA, "MH.Deletion complete=%d", err )
       
  2532         iSessionCommand = NULL;
       
  2533         iProtoStateFlags = 0;
       
  2534         iProtoState = MVtProtocolCommand::EIdle;
       
  2535         __VTPRINT( DEBUG_MEDIA, "MH.protoComC: EIdle uninit" )
       
  2536         if ( iPendingOp &&
       
  2537              iPendingOp->Command() == KVtEngTerminateSession )
       
  2538             {
       
  2539             __VTPRINT2( DEBUG_MEDIA, "MH.FinalUninit comp TerminateSession=%d",
       
  2540                 iPendingOp->Command())
       
  2541             CompleteOp( KErrNone );
       
  2542             }
       
  2543         else if ( iPendingOp ) {
       
  2544             __VTPRINT2( DEBUG_MEDIA, "MH.FinalUninit comp =%d",
       
  2545                 iPendingOp->Command() )
       
  2546             delete iPendingOp;
       
  2547             }
       
  2548         iPendingOp = NULL;
       
  2549         }
       
  2550     iPendingOps->Reset();
       
  2551     __VTPRINTEXIT( "MH.FinalUninit" )
       
  2552     }
       
  2553 
       
  2554 // -----------------------------------------------------------------------------
       
  2555 // CVtEngMediaHandler::ResetProto2WayL
       
  2556 // Resets protocol engine.
       
  2557 // -----------------------------------------------------------------------------
       
  2558 //
       
  2559 void CVtEngMediaHandler::ResetProto2WayL()
       
  2560     {
       
  2561     __VTPRINTENTER( "MH.ResetProto2WayL" )
       
  2562     __ASSERT_ALWAYS( iProtoState == MVtProtocolCommand::ESetup,
       
  2563                       Panic( EVtEngPanicMediaHandlerOpStateFailure ) );
       
  2564 
       
  2565     __VTPRINT( DEBUG_MEDIA, "MH. Calling ResetL on Proto" )
       
  2566     iUpdateVolumeAllowed = EFalse;
       
  2567     TInt cmdId = iSessionCommand->ResetProtocolL();
       
  2568     if ( cmdId > 0 )
       
  2569         {
       
  2570         // Add the operation if ok
       
  2571         AddOperation( EDestructProtoPhaseReset, cmdId, EFalse );
       
  2572         iProtoState = MVtProtocolCommand::EResetting;
       
  2573         }
       
  2574     else
       
  2575         {
       
  2576         __VTPRINT( DEBUG_MEDIA,
       
  2577             "MH.ResetProto2WayL waiting for cancel to complete" )
       
  2578         }
       
  2579     __VTPRINTEXIT( "MH.ResetProto2WayL" )
       
  2580     }
       
  2581 
       
  2582 // -----------------------------------------------------------------------------
       
  2583 // CVtEngMediaHandler::SetSelectedCameraId
       
  2584 // Called from Local video when camera has been selected.
       
  2585 // -----------------------------------------------------------------------------
       
  2586 //
       
  2587 void CVtEngMediaHandler::SetSelectedCameraId(
       
  2588     const TCameraId aId,
       
  2589     TBool aUpdateRequired )
       
  2590     {
       
  2591     __VTPRINTENTER( "MH.SetSelectedCameraId" )
       
  2592     __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL, "MH.SetSelectedCameraId id=%d", aId )
       
  2593     iSelectedCameraId = aId;
       
  2594     // Set flag that switch should be done later if
       
  2595     // engine has not reached proper state
       
  2596     // - but only if active provider is a camera.
       
  2597     if ( aUpdateRequired && iLocalVideo )
       
  2598         // NULL if called inside CVtEngLocalVideo::ConstructL
       
  2599         {
       
  2600         const CVtEngLocalVideo::TVtEngProviderType
       
  2601             activeProvider( iLocalVideo->ActiveProvider() );
       
  2602 
       
  2603         if ( activeProvider == CVtEngLocalVideo::KVtEngProviderCam1 ||
       
  2604             activeProvider == CVtEngLocalVideo::KVtEngProviderCam2 )
       
  2605             {
       
  2606             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  2607                 "MH. ESourceUpdateNeeded flag set" )
       
  2608             SetFlag( ESourceUpdateNeeded );
       
  2609             }
       
  2610         }
       
  2611     __VTPRINTEXIT( "MH.SetSelectedCameraId" )
       
  2612     }
       
  2613 
       
  2614 // -----------------------------------------------------------------------------
       
  2615 // CVtEngMediaHandler::HandleLocalVideoOperationCompleteL
       
  2616 // Asynchronous local video operation is completed in here.
       
  2617 // -----------------------------------------------------------------------------
       
  2618 //
       
  2619 void CVtEngMediaHandler::HandleLocalVideoOperationCompleteL(
       
  2620     const TInt aResult )
       
  2621     {
       
  2622     __VTPRINTENTER( "MH.LocVidOpComp" )
       
  2623     __VTPRINT3( DEBUG_MEDIA, "MH.LocVidOpComp res=%d,intOps=%d",
       
  2624         aResult, iPendingOps->Count() )
       
  2625     __VTPRINT2( DEBUG_MEDIA, "MH.LocVidOpComp state flags=%d", iProtoStateFlags )
       
  2626 
       
  2627     // Check if video should be paused
       
  2628     if ( IsFlag( EProtoPauseVideoBlankProv ) )
       
  2629         {
       
  2630         __VTPRINT( DEBUG_MEDIA, "MH.LocVidOpComp pause flagged" )
       
  2631         if ( aResult == KErrNone )
       
  2632             {
       
  2633             __VTPRINT( DEBUG_MEDIA, "MH.LocVidOpComp pausing" )
       
  2634             EnableVideoL( EFalse );
       
  2635             // Not ready yet, clear the two stages and complete in the end
       
  2636             if ( IsFlag( ETwoStageOperation ) &&
       
  2637                 IsFlag( EProtoContVideoBlankInit ) )
       
  2638                 {
       
  2639                 __VTPRINT( DEBUG_MEDIA, "MH.LocVidOpComp 1 stage complete" )
       
  2640                 ClearFlag( ETwoStageOperation );
       
  2641                 ClearFlag( EProtoContVideoBlankInit );
       
  2642                 }
       
  2643             ClearFlag( EProtoPauseVideoBlankProv );
       
  2644             }
       
  2645         }
       
  2646 
       
  2647     if ( iRequestStatus )
       
  2648         {
       
  2649         if ( iVSInitState == EStateInitStillImage )
       
  2650 
       
  2651             { // still image initialized, proceed to initializing blank provider
       
  2652             InitializeProviderL( *iRequestStatus );
       
  2653             __VTPRINTEXIT( "MH.LocVidOpComp" )
       
  2654             return;
       
  2655             }
       
  2656         else if ( iVSInitState == EStateInitProvider  )
       
  2657             {
       
  2658             __VTPRINT( DEBUG_MEDIA, "MH.LocVidOpComp reqComplete" )
       
  2659             // Part of media handler initialization
       
  2660             User::RequestComplete( iRequestStatus, aResult );
       
  2661             iRequestStatus = NULL;
       
  2662             iVSInitState = EInitStateNone;
       
  2663             __VTPRINTEXIT( "MH.LocVidOpComp" )
       
  2664             return;
       
  2665             }
       
  2666         else if ( iVSInitState == EStateWaitingProviderChangeForUninit )
       
  2667             {
       
  2668             iVSInitState = EInitStateNone;
       
  2669             iLocalVideo->StopViewFinder(); // ensure view finder is stopped
       
  2670             ContinueUninitializeL( EDestructInternals );
       
  2671             __VTPRINTEXIT( "MH.LocVidOpComp" )
       
  2672             return;
       
  2673             }
       
  2674         else if ( iVSInitState == EStateInitCanceled )
       
  2675             {
       
  2676             // If the request status has been cancelled
       
  2677             // uninitialize VT
       
  2678             ContinueUninitializeL( EDestructSwitchBlank );
       
  2679             }
       
  2680         }
       
  2681 
       
  2682     // Either complete the operation or remove 2 stage flag.
       
  2683     // If flag removed, the operation will be completed when
       
  2684     // the second stage finalizes.
       
  2685     if ( IsFlag( ETwoStageOperation ) )
       
  2686         {
       
  2687         SetFlag( EProtoSendIntraFrame );
       
  2688         ClearFlag( ETwoStageOperation );
       
  2689         }
       
  2690     else
       
  2691         {
       
  2692         // Send a sync message, if video enabled.
       
  2693         if ( !IsFlag( EProtoVideoTrackPaused ) &&
       
  2694             // and
       
  2695             iInitialized &&
       
  2696             iProtoState == MVtProtocolCommand::EConnected &&
       
  2697             iPendingOp &&
       
  2698             iPendingOp->Command() == KVtEngSetSource )
       
  2699             {
       
  2700             RequestFrame();
       
  2701             }
       
  2702         // Complete operation only if it is related. We may have received
       
  2703         // KVtEngTerminateSession while prepare/set source is pending and
       
  2704         // cannot complete it!
       
  2705         if ( iPendingOp )
       
  2706             {
       
  2707             switch( iPendingOp->Command() )
       
  2708                 {
       
  2709                 case KVtEngHandleLayoutChange:
       
  2710                 case KVtEngPrepareCamera:
       
  2711                 case KVtEngSetSource:
       
  2712                 case KVtEngUnfreeze:
       
  2713                     CompleteOp( aResult );
       
  2714                     break;
       
  2715 
       
  2716                 // Image sharing
       
  2717                 case KVtEngInitializeShareImage:
       
  2718                     __VTPRINT( DEBUG_MEDIA,
       
  2719                         "MH.LocVidOpComp KVtEngInitializeShareImage" )
       
  2720                     if ( aResult != KErrNone )
       
  2721                         {
       
  2722                         iLocalVideo->ShareError( aResult );
       
  2723                         }
       
  2724                     CompleteOp( aResult );
       
  2725                     break;
       
  2726 
       
  2727                 case KVtEngStartShareImage:
       
  2728                     __VTPRINT( DEBUG_MEDIA,
       
  2729                         "MH.LocVidOpComp KVtEngStartShareImage" )
       
  2730                     if ( aResult != KErrNone )
       
  2731                         {
       
  2732                         iLocalVideo->ShareError( aResult );
       
  2733                         }
       
  2734                     CompleteOp( aResult );
       
  2735                     if ( iVideoAction == EVideoActionEnable )
       
  2736                     	{
       
  2737                     	if ( aResult == KErrNone )
       
  2738                     		{
       
  2739                     		EnableVideoL( ETrue );
       
  2740                         	iVideoAction = EVideoActionDisable;
       
  2741                     		}
       
  2742                     	else
       
  2743                     		{
       
  2744                         	iVideoAction = EVideoActionNone;
       
  2745                     		}
       
  2746                         }
       
  2747 
       
  2748                     break;
       
  2749 
       
  2750                 case KVtEngStopShareImage:
       
  2751                     __VTPRINT( DEBUG_MEDIA,
       
  2752                         "MH.LocVidOpComp KVtEngStopShareImage" )
       
  2753                     if ( aResult != KErrNone )
       
  2754                         {
       
  2755                         iLocalVideo->ShareError( aResult );
       
  2756                         }
       
  2757                     CompleteOp( aResult );
       
  2758                     break;
       
  2759 
       
  2760                 default:
       
  2761                     break;
       
  2762                 }
       
  2763             }
       
  2764         }
       
  2765     __VTPRINTEXIT( "MH.LocVidOpComp" )
       
  2766     }
       
  2767 
       
  2768 // -----------------------------------------------------------------------------
       
  2769 // CVtEngMediaHandler::Disconnect
       
  2770 // Starts Protocol disconnecting procedure.
       
  2771 // -----------------------------------------------------------------------------
       
  2772 //
       
  2773 TInt CVtEngMediaHandler::Disconnect()
       
  2774     {
       
  2775     UninitializeNextStep();
       
  2776     return KErrNone;
       
  2777     }
       
  2778 
       
  2779 // -----------------------------------------------------------------------------
       
  2780 // CVtEngMediaHandler::SdkInitInfo
       
  2781 // Returns Protocol sdk initialization information.
       
  2782 // -----------------------------------------------------------------------------
       
  2783 //
       
  2784 TVtInitInfo& CVtEngMediaHandler::SdkInitInfo()
       
  2785     {
       
  2786     return iSdkInitInfo;
       
  2787     }
       
  2788 
       
  2789 // -----------------------------------------------------------------------------
       
  2790 // CVtEngMediaHandler::ProtoState
       
  2791 // Returns protocol state, maintained by VTEngine.
       
  2792 // Might be out of sync with actual Proto state.
       
  2793 // -----------------------------------------------------------------------------
       
  2794 //
       
  2795 MVtProtocolCommand::TVtProtocolState CVtEngMediaHandler::ProtoState()
       
  2796     {
       
  2797     return iProtoState;
       
  2798     }
       
  2799 
       
  2800 // -----------------------------------------------------------------------------
       
  2801 // CVtEngMediaHandler::Connect
       
  2802 // Sets up connection with remote end.
       
  2803 // -----------------------------------------------------------------------------
       
  2804 //
       
  2805 TInt CVtEngMediaHandler::Connect()
       
  2806     {
       
  2807     __VTPRINTENTER( "MH.Connect" )
       
  2808     __VTPRINT( DEBUG_MEDIA, "MH.Connect" )
       
  2809     TInt err( KErrNotReady );
       
  2810     if ( ProtoState() == MVtProtocolCommand::ESetup && IsFlag( EProto324IFAcquired ) )
       
  2811         {
       
  2812         TInt cmdId( 0 );
       
  2813         __VTPRINT( DEBUG_MEDIA, "MH. Calling ConnectToProtocolL on Proto" )
       
  2814         TRAP( err, cmdId = iSessionCommand->ConnectToProtocolL( ( ( CVtEngUtility::EngineUtils() )->Initializer() ).GetVtComms() ) );
       
  2815         if ( err == KErrNone )
       
  2816             {
       
  2817             const TInt res( AddOperation( EConnectProto, cmdId) );
       
  2818             if ( res < KErrNone )
       
  2819                 {
       
  2820                 err = res;
       
  2821                 }
       
  2822             iProtoState = MVtProtocolCommand::EConnecting;
       
  2823             __VTPRINT( DEBUG_MEDIA, "MH.protoComC: EConnecting Connecting" )
       
  2824             }
       
  2825         }
       
  2826     __VTPRINTEXITR( "MH.Connect err=%d", err )
       
  2827     return err;
       
  2828     }
       
  2829 
       
  2830 // -----------------------------------------------------------------------------
       
  2831 // CVtEngMediaHandler::AddVideoSource
       
  2832 // Adds video source.
       
  2833 // -----------------------------------------------------------------------------
       
  2834 //
       
  2835 TInt CVtEngMediaHandler::AddVideoSource( TUint aChannelId )
       
  2836     {
       
  2837     __VTPRINTENTER( "MH.AddVideoSource" )
       
  2838 
       
  2839     if( !MediaAddingValidity() )
       
  2840         return KErrCancel;
       
  2841 
       
  2842     TInt cmdId( 0 );
       
  2843     TRAPD( err, cmdId = iSessionCommand->AddVideoSourceL(
       
  2844         aChannelId, *iLocalVideo->Source() ) );
       
  2845     if ( err == KErrNone )
       
  2846         {
       
  2847         const TInt res( AddOperation( EAddVideoSource, cmdId ) );
       
  2848         if ( res >= KErrNone )
       
  2849             {
       
  2850             iRemoteMediaState |= EMediaVideoPreparing;
       
  2851             }
       
  2852         else
       
  2853             {
       
  2854             err = res;
       
  2855             }
       
  2856         }
       
  2857     if ( err != KErrNone )
       
  2858         {
       
  2859         CVtEngEventManager::NotifyEvent( KVtEngMediaInitFailure );
       
  2860         }
       
  2861     __VTPRINTEXITR( "MH.AddVideoSource %d", err )
       
  2862     return err;
       
  2863     }
       
  2864 
       
  2865 // -----------------------------------------------------------------------------
       
  2866 // CVtEngMediaHandler::AddAudioSource
       
  2867 // Adds audio source.
       
  2868 // -----------------------------------------------------------------------------
       
  2869 //
       
  2870 TInt CVtEngMediaHandler::AddAudioSource( TUint aChannelId )
       
  2871     {
       
  2872     __VTPRINTENTER( "MH.AddAudioSource" )
       
  2873 
       
  2874     if( !MediaAddingValidity() )
       
  2875         return KErrCancel;
       
  2876 
       
  2877     TInt cmdId( 0 );
       
  2878     TInt err( KErrNone );
       
  2879     // Only for target compilations.
       
  2880 #if !defined( __WINS__ )
       
  2881     err = iLocalVideo->CreateAudioSource();
       
  2882     if ( err == KErrNone )
       
  2883         {
       
  2884         TRAP( err, cmdId = iSessionCommand->AddAudioSourceL(
       
  2885             aChannelId, *iLocalVideo->AudioSource() ) );
       
  2886         }
       
  2887 #endif // !__WINS__
       
  2888 #if defined (__WINS__)
       
  2889 		aChannelId = aChannelId; // Remove compilation warnings with CW.
       
  2890 #endif // __WINS__
       
  2891 
       
  2892     if ( err == KErrNone )
       
  2893         {
       
  2894         const TInt res( AddOperation( EAddAudioSource, cmdId ) );
       
  2895         if ( res < KErrNone )
       
  2896             {
       
  2897             err = res;
       
  2898             }
       
  2899         }
       
  2900     if ( err != KErrNone )
       
  2901         {
       
  2902         CVtEngEventManager::NotifyEvent( KVtEngMediaInitFailure );
       
  2903         }
       
  2904     if ( IsFlag( ESourceUpdateNeeded ) )
       
  2905         {
       
  2906         __VTPRINT( DEBUG_MEDIA, "MH.AddASource updateProvider" )
       
  2907         ClearFlag( ESourceUpdateNeeded );
       
  2908         // Generate event
       
  2909         iLocalVideo->vsProvidersChanged(
       
  2910             iSelectedCameraId == MVtEngMedia::EPrimaryCamera );
       
  2911         }
       
  2912     __VTPRINTEXITR( "MH.AddAudioSource %d", err )
       
  2913     return err;
       
  2914     }
       
  2915 
       
  2916 // -----------------------------------------------------------------------------
       
  2917 // CVtEngMediaHandler::AddVideoSinkL
       
  2918 // Adds video sink.
       
  2919 // -----------------------------------------------------------------------------
       
  2920 //
       
  2921 TInt CVtEngMediaHandler::AddVideoSink( TUint aChannelId )
       
  2922     {
       
  2923     __VTPRINTENTER( "MH.AddVideoSink" )
       
  2924 
       
  2925     if( !MediaAddingValidity() )
       
  2926         return KErrCancel;
       
  2927 
       
  2928     TInt cmdId( 0 );
       
  2929     TRAPD( err, cmdId = iRemoteVideo->AddVideoSinkL( aChannelId ) );
       
  2930     if ( err == KErrNone )
       
  2931         {
       
  2932         const TInt res( AddOperation( EAddVideoSink, cmdId ) );
       
  2933         if ( res >= KErrNone )
       
  2934             {
       
  2935             iRemoteMediaState |= EMediaVideoPreparing;
       
  2936             }
       
  2937         else
       
  2938             {
       
  2939             err = res;
       
  2940             }
       
  2941         }
       
  2942     if ( err != KErrNone )
       
  2943         {
       
  2944         CVtEngEventManager::NotifyEvent( KVtEngMediaInitFailure );
       
  2945         }
       
  2946     __VTPRINTEXITR( "MH.AddVideoSink %d", err )
       
  2947     return err;
       
  2948     }
       
  2949 
       
  2950 // -----------------------------------------------------------------------------
       
  2951 // CVtEngMediaHandler::AddAudioSink
       
  2952 // Adds audio sink.
       
  2953 // -----------------------------------------------------------------------------
       
  2954 //
       
  2955 TInt CVtEngMediaHandler::AddAudioSink( TUint aChannelId )
       
  2956     {
       
  2957     __VTPRINTENTER( "MH.AddAudioSink" )
       
  2958 
       
  2959     if( !MediaAddingValidity() )
       
  2960         return KErrCancel;
       
  2961 
       
  2962     TInt cmdId( 0 );
       
  2963     TRAPD( err, cmdId = iRemoteVideo->AddAudioSinkL( aChannelId ) );
       
  2964     if ( err == KErrNone )
       
  2965         {
       
  2966         const TInt res( AddOperation( EAddAudioSink, cmdId ) );
       
  2967         if ( res >= KErrNone )
       
  2968             {
       
  2969             iRemoteMediaState |= EMediaAudioPreparing;
       
  2970             }
       
  2971         else
       
  2972             {
       
  2973             err = res;
       
  2974             }
       
  2975         }
       
  2976     if ( err != KErrNone )
       
  2977         {
       
  2978         CVtEngEventManager::NotifyEvent( KVtEngMediaInitFailure );
       
  2979         }
       
  2980     __VTPRINTEXITR( "MH.AddAudioSink %d", err )
       
  2981     return err;
       
  2982     }
       
  2983 
       
  2984 // -----------------------------------------------------------------------------
       
  2985 // CVtEngMediaHandler::RemoveOperation
       
  2986 // Removes an operation from stored operations.
       
  2987 // -----------------------------------------------------------------------------
       
  2988 //
       
  2989 template<class T>
       
  2990 TBool CVtEngMediaHandler::RemoveOperation( const T& aOp )
       
  2991     {
       
  2992     TBool removed( EFalse );
       
  2993     const TInt pos( IsPending( aOp ) );
       
  2994     if ( pos != KErrNotFound )
       
  2995         {
       
  2996         __VTPRINT3( DEBUG_MEDIA, "MH.RemoveOp removed index=%d TOperation=%d",
       
  2997             pos, ( *iPendingOps )[ pos ].iOp )
       
  2998         iPendingOps->Delete( pos );
       
  2999         removed = ETrue;
       
  3000         }
       
  3001     return removed;
       
  3002     }
       
  3003 
       
  3004 // -----------------------------------------------------------------------------
       
  3005 // CVtEngMediaHandler::AddOperation
       
  3006 // Adds operation to operations pending completion.
       
  3007 // -----------------------------------------------------------------------------
       
  3008 //
       
  3009 TInt CVtEngMediaHandler::AddOperation(
       
  3010     const TOperation aOp,
       
  3011     TInt aCmdId,
       
  3012     const TBool aResetExisting )
       
  3013     {
       
  3014     if ( aResetExisting )
       
  3015         {
       
  3016         iPendingOps->Reset();
       
  3017         }
       
  3018     TCmdOpPair opPair;
       
  3019     opPair.iOp = aOp;
       
  3020     opPair.iProtoCmdId = aCmdId;
       
  3021     // this should never leave because SetReserveL called in ConstructL
       
  3022     TRAPD( err, iPendingOps->AppendL( opPair ) );
       
  3023     if ( err != KErrNone )
       
  3024         {
       
  3025         CVtEngEventManager::NotifyEvent( KVtEngResourceMemAllocFailure );
       
  3026         return err;
       
  3027         }
       
  3028     const TInt count( iPendingOps->Count() );
       
  3029     __VTPRINT3( DEBUG_MEDIA, " MH.op added. op=%d,cmdId=%d", aOp, aCmdId )
       
  3030     __VTPRINT2( DEBUG_MEDIA, "              count=%d", count )
       
  3031     return ( count - 1 );
       
  3032     }
       
  3033 
       
  3034 // -----------------------------------------------------------------------------
       
  3035 // CVtEngMediaHandler::IsPending
       
  3036 // Checks if a command is set to be completed.
       
  3037 // Checking is done based on operation.
       
  3038 // -----------------------------------------------------------------------------
       
  3039 //
       
  3040 TInt CVtEngMediaHandler::IsPending( const TOperation aOp ) const
       
  3041     {
       
  3042     const TInt count( iPendingOps->Count() );
       
  3043     for ( TInt i = 0; i < count ; i++ )
       
  3044         {
       
  3045         if ( aOp == ( *iPendingOps )[ i ].iOp )
       
  3046             {
       
  3047             __VTPRINT2( DEBUG_MEDIA, "MH.IsPending VT Op index=%d", i )
       
  3048             return i;
       
  3049             }
       
  3050         }
       
  3051     __VTPRINT( DEBUG_MEDIA, "MH.IsPending VT Op NOT FOUND" )
       
  3052     return KErrNotFound;
       
  3053     }
       
  3054 
       
  3055 // -----------------------------------------------------------------------------
       
  3056 // CVtEngMediaHandler::IsPending
       
  3057 // Checks if a command is set to be completed.
       
  3058 // Checking is done based on command id.
       
  3059 // -----------------------------------------------------------------------------
       
  3060 //
       
  3061 TInt CVtEngMediaHandler::IsPending( const TInt aCmdId ) const
       
  3062     {
       
  3063     const TInt count( iPendingOps->Count() );
       
  3064     for ( TInt i = 0; i < count ; i++ )
       
  3065         {
       
  3066         if ( aCmdId == ( *iPendingOps )[ i ].iProtoCmdId )
       
  3067             {
       
  3068             __VTPRINT3( DEBUG_MEDIA, "MH.IsPending ProtoCmdId=%d index=%d",
       
  3069                 aCmdId, i )
       
  3070             return i;
       
  3071             }
       
  3072         }
       
  3073     __VTPRINT( DEBUG_MEDIA, "MH.IsPending ProtoCmdId NOT FOUND" )
       
  3074     return KErrNotFound;
       
  3075     }
       
  3076 
       
  3077 // -----------------------------------------------------------------------------
       
  3078 // CVtEngMediaHandler::CompleteOp
       
  3079 // Asynchronous command completion.
       
  3080 // -----------------------------------------------------------------------------
       
  3081 //
       
  3082 TInt CVtEngMediaHandler::CompleteOp( const TInt aResult )
       
  3083     {
       
  3084     CVtEngOperation* opToComplete = iPendingOp;
       
  3085     TInt err( KErrNotFound );
       
  3086     if ( opToComplete )
       
  3087         {
       
  3088         iPendingOp = NULL;
       
  3089         opToComplete->HandleOpComplete( aResult );
       
  3090         err = KErrNone;
       
  3091         }
       
  3092     return err;
       
  3093     }
       
  3094 
       
  3095 // -----------------------------------------------------------------------------
       
  3096 // CVtEngMediaHandler::AsyncCompleteOp
       
  3097 // Asynchronous command completion.
       
  3098 // -----------------------------------------------------------------------------
       
  3099 //
       
  3100 void CVtEngMediaHandler::AsyncCompleteOp( const TInt aResult )
       
  3101     {
       
  3102     iAsyncCallback->Cancel();
       
  3103     iAsyncCompleteOpResult = aResult;
       
  3104     iAsyncCallback->Start( TCallBack( DoCompleteOp, this ) );
       
  3105     }
       
  3106 
       
  3107 // -----------------------------------------------------------------------------
       
  3108 // CVtEngMediaHandler::MatchResponseToPendingOps
       
  3109 // Checks if a response matches corresponding operation.
       
  3110 // -----------------------------------------------------------------------------
       
  3111 //
       
  3112 TBool CVtEngMediaHandler::MatchResponseToPendingOps(
       
  3113     const TInt aProtoCmdId,
       
  3114     const TOperation aOperation,
       
  3115     TInt* aIndex )
       
  3116     {
       
  3117     const TInt index( IsPending( aOperation ) );
       
  3118     TBool entryFound( EFalse );
       
  3119     if ( index != KErrNotFound )
       
  3120         {
       
  3121         const TCmdOpPair opPair = ( *iPendingOps )[index];
       
  3122         if ( opPair.iProtoCmdId == aProtoCmdId )
       
  3123             {
       
  3124             entryFound = ETrue;
       
  3125             if ( aIndex )
       
  3126                 {
       
  3127                 *aIndex = index;
       
  3128                 }
       
  3129             }
       
  3130         }
       
  3131     __VTPRINT2( DEBUG_MEDIA, "MH.MatchRespToOp was found=%d", entryFound )
       
  3132     return entryFound;
       
  3133     }
       
  3134 
       
  3135 // -----------------------------------------------------------------------------
       
  3136 // CVtEngMediaHandler::StartDisconnectTimerL
       
  3137 // Starts the disconnect timer.
       
  3138 // -----------------------------------------------------------------------------
       
  3139 //
       
  3140 void CVtEngMediaHandler::StartDisconnectTimerL()
       
  3141     {
       
  3142     __VTPRINT( DEBUG_MEDIA, "MH. start disc.timer" )
       
  3143     if ( iTimer == NULL )
       
  3144         {
       
  3145         TCallBack cb( CVtEngMediaHandler::TimerCallback, NULL );
       
  3146         iTimer = CPeriodic::NewL( 0 );
       
  3147         iTimer->Start( KVtEngDisconnectionTimer,
       
  3148                    KVtEngDisconnectionTimer,
       
  3149                    cb );
       
  3150         }
       
  3151     }
       
  3152 
       
  3153 // -----------------------------------------------------------------------------
       
  3154 // CVtEngMediaHandler::NextUninitStepCallbackL
       
  3155 // Proceeds to next uninitializatioin step asynchronously.
       
  3156 // -----------------------------------------------------------------------------
       
  3157 //
       
  3158 void CVtEngMediaHandler::NextUninitStepCallbackL()
       
  3159     {
       
  3160     __VTPRINTENTER( "MH.NextUninitStepCallbackL" )
       
  3161     if ( !iNextStepCallback )
       
  3162         {
       
  3163         // perform asap => high priority
       
  3164         TCallBack cb( CVtEngMediaHandler::UninitCallback, this );
       
  3165         iNextStepCallback = new ( ELeave ) CAsyncCallBack(
       
  3166             cb, CActive::EPriorityHigh );
       
  3167         iNextStepCallback->CallBack();
       
  3168         }
       
  3169     __VTPRINTEXIT( "MH.NextUninitStepCallbackL" )
       
  3170     }
       
  3171 
       
  3172 // -----------------------------------------------------------------------------
       
  3173 // CVtEngMediaHandler::UninitCallback
       
  3174 // Asynch callback method for uninitialization.
       
  3175 // -----------------------------------------------------------------------------
       
  3176 //
       
  3177 TInt CVtEngMediaHandler::UninitCallback( TAny* aAny )
       
  3178     {
       
  3179     __VTPRINTENTER( "MH.UninitCallback" )
       
  3180     CVtEngMediaHandler* handler = static_cast<CVtEngMediaHandler*>( aAny );
       
  3181     delete handler->iNextStepCallback;
       
  3182     handler->iNextStepCallback = NULL;
       
  3183     handler->UninitializeNextStep();
       
  3184     __VTPRINTEXIT( "MH.UninitCallback" )
       
  3185     return KErrNone;
       
  3186     }
       
  3187 
       
  3188 // -----------------------------------------------------------------------------
       
  3189 // CVtEngMediaHandler::AssignPendingOp
       
  3190 // Assigns operation and completes pending if necessary.
       
  3191 // -----------------------------------------------------------------------------
       
  3192 //
       
  3193 TInt CVtEngMediaHandler::AssignPendingOp(
       
  3194             CVtEngOperation& aOperation,
       
  3195             TInt aReplaceError )
       
  3196     {
       
  3197     TInt result = KErrNone;
       
  3198     if ( iPendingOp )
       
  3199         {
       
  3200         if ( aReplaceError != KErrNone &&
       
  3201             // if terminating don't allow other commands
       
  3202              iPendingOp->Command() != KVtEngTerminateSession )
       
  3203             {
       
  3204             __VTPRINT2( DEBUG_MEDIA, "MH.Assign op replace err=", aReplaceError )
       
  3205             CompleteOp( aReplaceError );
       
  3206             // indicate previous operation was "cancelled" (even though it is
       
  3207             // not really cancelled, we still get callback!)
       
  3208             result = KErrCancel;
       
  3209             }
       
  3210         else
       
  3211             {
       
  3212             // not allowed to assign new operation
       
  3213             result = KErrGeneral;
       
  3214             }
       
  3215         }
       
  3216     if ( result != KErrGeneral )
       
  3217         {
       
  3218         __VTPRINT2( DEBUG_MEDIA, "MH.AssignPendingOp=%d", aOperation.Command() )
       
  3219         iPendingOp = &aOperation;
       
  3220         }
       
  3221     __VTPRINT2( DEBUG_MEDIA, "MH.AssignPendingOp.res=%d", result )
       
  3222     return result;
       
  3223     }
       
  3224 
       
  3225 // -----------------------------------------------------------------------------
       
  3226 // CVtEngMediaHandler::DoCompleteOp
       
  3227 // Implementation of command completion.
       
  3228 // -----------------------------------------------------------------------------
       
  3229 //
       
  3230 TInt CVtEngMediaHandler::DoCompleteOp( TAny* aAny )
       
  3231     {
       
  3232     CVtEngMediaHandler* self = static_cast< CVtEngMediaHandler* >( aAny );
       
  3233     self->CompleteOp( self->iAsyncCompleteOpResult );
       
  3234     self->iAsyncCompleteOpResult = KErrNone;
       
  3235     return KErrNone;
       
  3236     }
       
  3237 
       
  3238 // -----------------------------------------------------------------------------
       
  3239 // CVtEngMediaHandler::GetPendingCommand
       
  3240 //
       
  3241 // -----------------------------------------------------------------------------
       
  3242 //
       
  3243 TVtEngCommandId CVtEngMediaHandler::GetPendingCommand()
       
  3244     {
       
  3245     if ( iPendingOp )
       
  3246         {
       
  3247         return iPendingOp->Command();
       
  3248         }
       
  3249     return KVtEngCommandNone;
       
  3250     }
       
  3251 
       
  3252 // -----------------------------------------------------------------------------
       
  3253 // CVtEngMediaHandler::AssertFlag
       
  3254 // Checks flag's validity.
       
  3255 // -----------------------------------------------------------------------------
       
  3256 //
       
  3257 #ifdef _DEBUG
       
  3258 void CVtEngMediaHandler::AssertFlag( const TInt aFlag ) const
       
  3259 #else
       
  3260 void CVtEngMediaHandler::AssertFlag( const TInt /* aFlag */ ) const
       
  3261 #endif // _DEBUG
       
  3262     {
       
  3263     __ASSERT_DEBUG(
       
  3264         aFlag == EProtoAudioSourceAdded ||
       
  3265         aFlag == EProtoVideoSourceAdded ||
       
  3266         aFlag == EProtoAudioSinkAdded ||
       
  3267         aFlag == EProtoVideoSinkAdded ||
       
  3268         aFlag == EProtoAudioTrackPaused ||
       
  3269         aFlag == EProtoVideoTrackPaused ||
       
  3270         aFlag == ETwoStageOperation ||
       
  3271         aFlag == EProtoPauseVideoRequested ||
       
  3272         aFlag == EProtoPauseVideoBlankProv ||
       
  3273         aFlag == EProtoContVideoBlankProv ||
       
  3274         aFlag == EProtoContVideoBlankInit ||
       
  3275         aFlag == ESourceUpdateNeeded ||
       
  3276         aFlag == EProtoSendIntraFrame ||
       
  3277         aFlag == EProto324IFAcquired ||
       
  3278         aFlag == EProtoCancelProtoCmdsOk ||
       
  3279         aFlag == EVideoQualitySetByPeer ||
       
  3280         aFlag == EOutVideoChannelClosed ||
       
  3281         aFlag == EOutAudioChannelClosed,
       
  3282         Panic( EVtEngPanicInvalidFlag ) );
       
  3283     }
       
  3284 
       
  3285 // -----------------------------------------------------------------------------
       
  3286 // CVtEngMediaHandler::IsFlag
       
  3287 // Checks if a certain flag is set.
       
  3288 // -----------------------------------------------------------------------------
       
  3289 //
       
  3290 TBool CVtEngMediaHandler::IsFlag( const TInt aFlag ) const
       
  3291     {
       
  3292     AssertFlag( aFlag );
       
  3293     if ( iProtoStateFlags & aFlag )
       
  3294         {
       
  3295         return ETrue;
       
  3296         }
       
  3297     else
       
  3298         {
       
  3299         return EFalse;
       
  3300         }
       
  3301     }
       
  3302 
       
  3303 // -----------------------------------------------------------------------------
       
  3304 // CVtEngMediaHandler::SetFlag
       
  3305 // Sets flag on.
       
  3306 // -----------------------------------------------------------------------------
       
  3307 //
       
  3308 void CVtEngMediaHandler::SetFlag( const TInt aFlag )
       
  3309     {
       
  3310     AssertFlag( aFlag );
       
  3311     iProtoStateFlags |= aFlag;
       
  3312     }
       
  3313 
       
  3314 // -----------------------------------------------------------------------------
       
  3315 // CVtEngMediaHandler::ClearFlag
       
  3316 // Removes a flag.
       
  3317 // -----------------------------------------------------------------------------
       
  3318 //
       
  3319 void CVtEngMediaHandler::ClearFlag( const TInt aFlag )
       
  3320     {
       
  3321     AssertFlag( aFlag );
       
  3322     iProtoStateFlags &= ~aFlag;
       
  3323     }
       
  3324 
       
  3325 // -----------------------------------------------------------------------------
       
  3326 // CVtEngMediaHandler::SetVolume
       
  3327 // Sets volume values to Protocol.
       
  3328 // -----------------------------------------------------------------------------
       
  3329 //
       
  3330 TInt CVtEngMediaHandler::SetVolume(
       
  3331     const TInt aVolume,
       
  3332     CVtEngOperation* aOperation )
       
  3333     {
       
  3334     __VTPRINTENTER( "MH.SetVolume" )
       
  3335     TInt res( KErrNotFound );
       
  3336     __VTPRINT2( DEBUG_MEDIA, " vol=%d", aVolume )
       
  3337     if ( iAudioCtrl )
       
  3338         {
       
  3339         TInt id( 0 );
       
  3340         // Max volume cannot be zero.
       
  3341         TInt vol( ( CVtEngUtility::Settings().ValidVolume( aVolume ) ) *
       
  3342             ( iProtoMaxVolume / CVtEngUtility::Settings().MaxVolume() ) );
       
  3343         __VTPRINT2( DEBUG_MEDIA, "CVtEngMediaHandler::SetVolumeL, vol=%d", vol )
       
  3344         TRAP( res, id = iAudioCtrl->SetAudioVolumeL( vol ) );
       
  3345         if ( res == KErrNone )
       
  3346             {
       
  3347             AddOperation( ESetAudioVolume, id );
       
  3348             if( aOperation )
       
  3349                 {
       
  3350                 AssignPendingOp( *aOperation );
       
  3351                 }
       
  3352             }
       
  3353         }
       
  3354     __VTPRINTEXITR( "MH.SetVolume %d", res )
       
  3355     return res;
       
  3356     }
       
  3357 
       
  3358 // -----------------------------------------------------------------------------
       
  3359 // CVtEngMediaHandler::RequestAudioControllerL
       
  3360 // Requests controllers for audio output and input
       
  3361 // -----------------------------------------------------------------------------
       
  3362 //
       
  3363 TBool CVtEngMediaHandler::RequestAudioControllerL()
       
  3364     {
       
  3365     __VTPRINTENTER( "MH.RequestAudioControllerL" )
       
  3366     __VTPRINT( DEBUG_MEDIA, "MH.RequestAudioControllerL" )
       
  3367     __ASSERT_ALWAYS(iSessionCommand, Panic( EVtEngPanicInvalidAudioPointer ) );
       
  3368 
       
  3369     TInt id( 0 );
       
  3370     iAudioCtrl = VTProtocolFactory::GetAudioConfigCommandL(iRemoteVideo->AudioSink());
       
  3371 
       
  3372     if ( !iAudioCtrl )
       
  3373         {
       
  3374         CVtEngEventManager::NotifyEvent( KVtEngMediaInitFailure );
       
  3375         __VTPRINTEXIT( "MH.RequestAudioControllerL Failed" )
       
  3376         return EFalse;
       
  3377         }
       
  3378     iAudioCtrl->SetObserverL( this );
       
  3379 
       
  3380     // Get the max value for Protocol volume
       
  3381     TRAPD ( res, id = iAudioCtrl->GetMaxAudioVolumeL( iProtoMaxVolume ) ) ;
       
  3382     __VTPRINT2( DEBUG_MEDIA, "MH.RequestAudioControllerL: err=%d",res )
       
  3383     if ( res != KErrNone)
       
  3384         {
       
  3385         CVtEngEventManager::NotifyEvent( KVtEngMediaInitFailure );
       
  3386         __VTPRINTEXIT( "MH.RequestAudioControllerL" )
       
  3387         return EFalse;
       
  3388         }
       
  3389 
       
  3390     res = AddOperation( EGetAudioGetMaxVolume, id );
       
  3391     if ( res < KErrNone ) // res is index
       
  3392         {
       
  3393         CVtEngEventManager::NotifyEvent( KVtEngMediaInitFailure );
       
  3394         __VTPRINT2( DEBUG_MEDIA, "MH.RequestAudioControllerL::res=%d", res )
       
  3395         }
       
  3396     __VTPRINTEXIT( "MH.RequestAudioControllerL" )
       
  3397     return ETrue;
       
  3398     }
       
  3399 
       
  3400 
       
  3401 // -----------------------------------------------------------------------------
       
  3402 // CVtEngMediaHandler::HandleSpatialTradeoffIndication
       
  3403 //
       
  3404 // -----------------------------------------------------------------------------
       
  3405 //
       
  3406 void CVtEngMediaHandler::HandleSpatialTradeoffIndication(
       
  3407     const TUint16 aLogicalChannelId, const TUint8 aTradeOff )
       
  3408     {
       
  3409     __VTPRINTENTER( "MH.HandleSpatialTradeoffIndication" )
       
  3410     __VTPRINT3( DEBUG_MEDIA,
       
  3411         "MH.HandleSpatialTradeoffIndication id=%d tradeOff=%d",
       
  3412         aLogicalChannelId, aTradeOff )
       
  3413     ( void ) aLogicalChannelId;
       
  3414     iVideoQuality.UpdateVideoQuality( iVideoQuality.FromTradeOff( aTradeOff ) );
       
  3415     __VTPRINTEXIT( "MH.HandleSpatialTradeoffIndication" )
       
  3416     }
       
  3417 
       
  3418 // -----------------------------------------------------------------------------
       
  3419 // CVtEngMediaHandler::HandleSpatialTradeoffCommandL
       
  3420 //
       
  3421 // -----------------------------------------------------------------------------
       
  3422 //
       
  3423 void CVtEngMediaHandler::HandleSpatialTradeoffCommandL(
       
  3424     const TUint16, const TUint8 aTradeOff )
       
  3425     {
       
  3426     __VTPRINTENTER( "MH.HandleSpatialTradeoffCommandL" )
       
  3427     SetVideoQualityL( iVideoQuality.FromTradeOff( aTradeOff ), EFalse );
       
  3428     __VTPRINTEXIT( "MH.HandleSpatialTradeoffCommandL" )
       
  3429     }
       
  3430 
       
  3431 // -----------------------------------------------------------------------------
       
  3432 // CVtEngMediaHandler::EnableVideoL
       
  3433 // Enables/Disables video sending.
       
  3434 // -----------------------------------------------------------------------------
       
  3435 //
       
  3436 CVtEngMediaHandler::TOperation CVtEngMediaHandler::EnableVideoL(
       
  3437     const TBool aEnable, const TOperation aOp )
       
  3438     {
       
  3439     __VTPRINTENTER( "MH.EnableVideoL" )
       
  3440     __VTPRINT3( DEBUG_MEDIA | DEBUG_DETAIL, "MH.EnableV en=%d state=%d",
       
  3441         aEnable, iProtoState )
       
  3442     TInt cmdId( 0 );
       
  3443     TInt err( KErrNone );
       
  3444     TOperation op( ENone );
       
  3445     MVtEngMedia::TMediaSource currentSource;
       
  3446     GetSource( currentSource );
       
  3447 
       
  3448     // Videosource is added and Protocol is in connected state.
       
  3449     if ( IsFlag( EProtoVideoSourceAdded ) && iSessionCommand )
       
  3450         {
       
  3451         __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL, "MH.EnableV source=%d",
       
  3452             currentSource )
       
  3453         // Has an actual source been selected.
       
  3454         if ( ( currentSource == EMediaNone ) || ( currentSource == EMediaShare ) )
       
  3455             {
       
  3456                 __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.EnaLocVideo blank" )
       
  3457             if ( aEnable && IsPending( EEnableVideo) == KErrNotFound )
       
  3458                 {
       
  3459                 ClearFlag( EProtoPauseVideoRequested );
       
  3460                 __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH. Calling ResumeL on Protocol" )
       
  3461                 TRAP( err, cmdId = iSessionCommand->ResumeVideoL( *iLocalVideo->Source() ) );
       
  3462                 if ( err != KErrNone )
       
  3463                     {
       
  3464                     // Log the error and leave, UI handles the rest
       
  3465                     __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL,
       
  3466                         "MH.EnaLocVideo PauseL left=%d", err )
       
  3467                     __VTPRINTEXIT( "MH.EnableVideoL" )
       
  3468                     User::Leave( err );
       
  3469                     }
       
  3470                 else
       
  3471                     {
       
  3472                     op = aOp;
       
  3473                     AddOperation( aOp, cmdId );
       
  3474                     }
       
  3475                 }
       
  3476             // Video to be paused.
       
  3477             else if( !aEnable && IsPending( EDisableVideo ) )
       
  3478                 {
       
  3479                 op = DoPauseVideo();
       
  3480                 }
       
  3481             }
       
  3482         else // camera or still image
       
  3483             {
       
  3484             if ( !aEnable && IsPending( EDisableVideo ) )
       
  3485                 {
       
  3486                 // Pause video
       
  3487                 op = DoPauseVideo();
       
  3488                 }
       
  3489             }
       
  3490         }
       
  3491     else // Not connected and sources not added yet
       
  3492         {
       
  3493         __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.enavideo not conn" )
       
  3494         // If we are initializing, then this has to be executed
       
  3495         if ( IsFlag( EProtoContVideoBlankProv ) )
       
  3496             {
       
  3497             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.enavideo blank cont" )
       
  3498             ClearFlag( EProtoContVideoBlankProv );
       
  3499             SetFlag( EProtoContVideoBlankInit );
       
  3500             }
       
  3501 
       
  3502         if ( aEnable )
       
  3503             {
       
  3504             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.EnableV clear pending" )
       
  3505             // Ensure that video sending is enabled in data source.
       
  3506             iLocalVideo->ResumeVideoSending();
       
  3507             ClearFlag( EProtoPauseVideoRequested );
       
  3508             }
       
  3509         else
       
  3510             {
       
  3511             iLocalVideo->PauseVideoSending();
       
  3512             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL, "MH.EnableV set pending" )
       
  3513             SetFlag( EProtoPauseVideoRequested );
       
  3514             }
       
  3515         }
       
  3516 
       
  3517     __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL, "MH.EnableV=%d", err )
       
  3518     __VTPRINTEXITR( "MH.EnableVideoL %d", op )
       
  3519     return op;
       
  3520     }
       
  3521 
       
  3522 // -----------------------------------------------------------------------------
       
  3523 // CVtEngMediaHandler::DoPauseVideo
       
  3524 // Does video pausing.
       
  3525 // -----------------------------------------------------------------------------
       
  3526 //
       
  3527 CVtEngMediaHandler::TOperation CVtEngMediaHandler::DoPauseVideo()
       
  3528     {
       
  3529     __VTPRINTENTER( "MH.DoPauseVideo" )
       
  3530     TInt cmdId( 0 );
       
  3531     TOperation op( ENone );
       
  3532     __VTPRINT( DEBUG_MEDIA, "MH. Calling PauseL on Protocol" )
       
  3533     TRAPD( err, cmdId = iSessionCommand->PauseVideoL( *iLocalVideo->Source() ) );
       
  3534     if ( err != KErrNone )
       
  3535         {
       
  3536         __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL,
       
  3537             "MH.DoPauseVideo PauseL left=%d", err )
       
  3538         // Remove the 2 stage flag, since PauseL failed.
       
  3539         // Command should be completed.
       
  3540         if( IsFlag( ETwoStageOperation ) )
       
  3541             {
       
  3542             __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  3543                 "   Disable 2 stage clearance" )
       
  3544             ClearFlag( ETwoStageOperation );
       
  3545             }
       
  3546         }
       
  3547     else
       
  3548         {
       
  3549         AddOperation( EDisableVideo, cmdId );
       
  3550         op = EDisableVideo;
       
  3551         __VTPRINT( DEBUG_MEDIA | DEBUG_DETAIL,
       
  3552             "MH.DisaLocVideo PauseL issued" )
       
  3553         }
       
  3554     ClearFlag( EProtoPauseVideoRequested );
       
  3555     __VTPRINTEXITR( "MH.DoPauseVideo %d", op )
       
  3556     return op;
       
  3557     }
       
  3558 
       
  3559 // -----------------------------------------------------------------------------
       
  3560 // CVtEngMediaHandler::HandleAudioOutputControlCommandComplete
       
  3561 // Callback function for audio controller commands.
       
  3562 // -----------------------------------------------------------------------------
       
  3563 //
       
  3564 void CVtEngMediaHandler::HandleAudioOutputControlCommandComplete(TInt aId,
       
  3565     TVtAudioOutputControlCommand aCmd,
       
  3566     TAny* /*aContextData*/,
       
  3567     TInt aStatus)
       
  3568     {
       
  3569     __VTPRINTENTER( "MH.HandleAudioOutputControlCommandComplete" )
       
  3570     __VTPRINT2( DEBUG_MEDIA, "MH.AudioComC CMD=%d", aCmd )
       
  3571     __VTPRINT2( DEBUG_MEDIA, "MH.AudioComC cmdId=%d", aId )
       
  3572     __VTPRINT2( DEBUG_MEDIA, "MH.AudioComC stat=%d", aStatus )
       
  3573 
       
  3574     switch ( aCmd )
       
  3575         {
       
  3576         case EVtAudioOutputControlGetMaxVolume:
       
  3577             RemoveOperation( aId );
       
  3578             InitializeVolume();
       
  3579             break;
       
  3580         case EVtAudioOutputControlSetVolume:
       
  3581             __VTPRINT2( DEBUG_MEDIA, "MH.protoComC SetVolume=%d",
       
  3582                 iUpdateVolumeRequired )
       
  3583 
       
  3584             RemoveOperation( aId );
       
  3585 
       
  3586             if ( iUpdateVolumeRequired )
       
  3587                 {
       
  3588                 iUpdateVolumeRequired = EFalse;
       
  3589                 UpdateVolume();
       
  3590                 }
       
  3591 
       
  3592             if ( IsPending( ESetAudioVolume ) == KErrNotFound &&
       
  3593                  iPendingOp == iPendingVolumeOp )
       
  3594                 {
       
  3595                 iPendingVolumeOp = NULL;
       
  3596                 CompleteOp( aStatus );
       
  3597                 }
       
  3598             break;
       
  3599         case EVtAudioOutputControlGetBalance:
       
  3600         case EVtAudioOutputControlSetBalance:
       
  3601         case EVtAudioOutputControlGetVolume:
       
  3602         default:
       
  3603             break;
       
  3604         }
       
  3605     __VTPRINTEXIT( "MH.HandleAudioOutputControlCommandComplete" )
       
  3606     }
       
  3607 
       
  3608 // -----------------------------------------------------------------------------
       
  3609 // CVtEngMediaHandler::InitializeVolume
       
  3610 // Sets the 'beginning' values for volume.
       
  3611 // -----------------------------------------------------------------------------
       
  3612 //
       
  3613 void CVtEngMediaHandler::InitializeVolume()
       
  3614     {
       
  3615     __VTPRINT2( DEBUG_MEDIA, "MH.InitializeVolume: max vol=%d", iProtoMaxVolume )
       
  3616     iUpdateVolumeAllowed = ETrue;
       
  3617     UpdateVolume();
       
  3618     if ( iLocalVideo )
       
  3619         {
       
  3620         iLocalVideo->UnMute();
       
  3621         }
       
  3622     }
       
  3623 
       
  3624 // -----------------------------------------------------------------------------
       
  3625 // CVtEngMediaHandler::DisconnectProtoL
       
  3626 // Does the disconnecting of Protocol.
       
  3627 // -----------------------------------------------------------------------------
       
  3628 //
       
  3629 void CVtEngMediaHandler::DisconnectProtoL()
       
  3630     {
       
  3631     __VTPRINTENTER( "MH.DisconnectProtoL" )
       
  3632     __VTPRINT2( DEBUG_MEDIA, "MH.DisconnectProto with Protocol state=%d",
       
  3633         iProtoState )
       
  3634     TInt cmdId( 0 );
       
  3635     // The two states that require disconnecting
       
  3636     if ( iProtoState == MVtProtocolCommand::EConnected ||
       
  3637          iProtoState == MVtProtocolCommand::EConnecting )
       
  3638         {
       
  3639         __VTPRINT( DEBUG_MEDIA, "MH. Calling DisconnectFromProtocolL on Protocol" )
       
  3640         TRAPD( err, cmdId = iSessionCommand->DisconnectFromProtocolL() );
       
  3641         if ( err == KErrNone )
       
  3642             {
       
  3643             __VTPRINT( DEBUG_MEDIA, "MH.protoCom: Disconnecting" )
       
  3644             AddOperation( EDestructProtoPhaseDisconnect, cmdId );
       
  3645             iProtoState = MVtProtocolCommand::EDisconnecting;
       
  3646             StartDisconnectTimerL();
       
  3647             }
       
  3648         else
       
  3649             {
       
  3650             // Canceling the disconnect to notify that it has failed
       
  3651             __VTPRINT2( DEBUG_MEDIA, "MH.DisconnectProto erronous=%d", err )
       
  3652             cmdId = err;
       
  3653             }
       
  3654         }
       
  3655     else {
       
  3656         cmdId = KErrNotSupported;
       
  3657         }
       
  3658     __VTPRINTEXITR( "MH.DisconnectProtoL cmdId=%d", cmdId )
       
  3659     }
       
  3660 
       
  3661 // -----------------------------------------------------------------------------
       
  3662 // CVtEngMediaHandler::CancelAllProtoCommands
       
  3663 // Cancels all commands pending for execution in Proto.
       
  3664 // -----------------------------------------------------------------------------
       
  3665 //
       
  3666 TInt CVtEngMediaHandler::CancelAllProtoCommands( TOperation &aOp )
       
  3667     {
       
  3668     __VTPRINTENTER( "MH.CancelAllProtoCommands" )
       
  3669     TInt err( KErrNotReady );
       
  3670     aOp = ENone;
       
  3671     if ( IsPending( EUninitializeCancelAllProto ) != KErrNotFound )
       
  3672         {
       
  3673         aOp = EUninitializeCancelAllProto;
       
  3674         // Indicate difference from started cancellation with error code.
       
  3675         err = KErrAlreadyExists;
       
  3676         }
       
  3677     else if ( iSessionCommand && iPendingOps && !IsFlag( EProtoCancelProtoCmdsOk ) )
       
  3678         {
       
  3679         if ( iPendingOps->Count() )
       
  3680             {
       
  3681             __VTPRINT( DEBUG_MEDIA, "MH. Calling CancelAllCommandsL on Proto" )
       
  3682             TInt cmdId( 0 );
       
  3683             TRAP( err, ( cmdId = iSessionCommand->CancelAllCommandsL() ) );
       
  3684             __VTPRINT2( DEBUG_MEDIA | DEBUG_DETAIL,
       
  3685                     "MH.CancelAllProtoCommands cmdId=%d", cmdId )
       
  3686             if ( cmdId && err == KErrNone )
       
  3687                 {
       
  3688                 aOp =  EUninitializeCancelAllProto;
       
  3689                 SetFlag( EProtoCancelProtoCmdsOk );
       
  3690                 AddOperation( aOp, cmdId );
       
  3691                 }
       
  3692             // completes in CommandCompletedL
       
  3693             }
       
  3694         else {
       
  3695             // mark there's nothing to cancel
       
  3696             SetFlag( EProtoCancelProtoCmdsOk );
       
  3697             }
       
  3698         }
       
  3699     __VTPRINTEXITR( "MH.CancelAllProtoCommands err=%d", err )
       
  3700     return err;
       
  3701     }
       
  3702 
       
  3703 // -----------------------------------------------------------------------------
       
  3704 // CVtEngMediaHandler::ProtoInitialized
       
  3705 // Proto init completed.
       
  3706 // -----------------------------------------------------------------------------
       
  3707 //
       
  3708 TBool CVtEngMediaHandler::ProtoInitialized() const
       
  3709     {
       
  3710     return iSessionCommand ? ETrue : EFalse;
       
  3711     }
       
  3712 
       
  3713 // -----------------------------------------------------------------------------
       
  3714 // CVtEngMediaHandler::TimerCallback
       
  3715 // Callback method for timer expiration.
       
  3716 // -----------------------------------------------------------------------------
       
  3717 //
       
  3718 TInt CVtEngMediaHandler::TimerCallback( TAny* /*aAny*/ )
       
  3719     {
       
  3720     __VTPRINT( DEBUG_MEDIA, "MH.TimerCallback -> PANIC " )
       
  3721     Panic( EVtEngPanicDisconnectTimerExpired );
       
  3722     return KErrNone;
       
  3723     }
       
  3724 
       
  3725 // -----------------------------------------------------------------------------
       
  3726 // CVtEngMediaHandler::SetVersionInfoL
       
  3727 // Sets version information to Proto.
       
  3728 // -----------------------------------------------------------------------------
       
  3729 //
       
  3730 void CVtEngMediaHandler::SetVersionInfoL( )
       
  3731     {
       
  3732     __VTPRINTENTER( "MH.SetVersionInfoL" )
       
  3733 
       
  3734     if ( !iH324Config )
       
  3735         {
       
  3736         __VTPRINT( DEBUG_MEDIA, "MH.SetVersion not ready" )
       
  3737         User::Leave( KErrNotReady );
       
  3738         }
       
  3739 
       
  3740     // Current new line character index
       
  3741     TInt index( 0 );
       
  3742 
       
  3743     // Version information from SysUtil
       
  3744     HBufC* versionInfo16 = HBufC::NewLC( KVtEngSwVersionTextLength );
       
  3745 
       
  3746     // Pointer to SysUtil versionInfo descriptor. Temporary pointer to
       
  3747     // handle data.
       
  3748     TPtr versionInfoptr16( versionInfo16->Des() );
       
  3749 
       
  3750     // SW Version and product information buffers to be send to peer.
       
  3751     HBufC8* version = HBufC8::NewLC( KVtEngSwVersionTextLength );
       
  3752     HBufC8* product = HBufC8::NewLC( KVtEngSwVersionTextLength );
       
  3753     TPtr8 versionPtr8( version->Des() );
       
  3754     TPtr8 productPtr8( product->Des() );
       
  3755 
       
  3756     // Marker for line ending '\n'
       
  3757     const TChar endLine( KVtEngCharacterEndLine );
       
  3758 
       
  3759     TInt err = ( SysUtil::GetSWVersion( versionInfoptr16 ) );
       
  3760     if ( err != KErrNone || !versionInfoptr16.Length() )
       
  3761         {
       
  3762         __VTPRINT2( DEBUG_MEDIA, "MH.SetVersion SU: %d", err )
       
  3763         __VTPRINTEXIT( "MH.SetVersionInfoL" )
       
  3764         return;
       
  3765         }
       
  3766 #ifdef VTDEBUG
       
  3767     RDebug::Print( _L("SysUtil::GetSWVersion: %s"), versionInfoptr16.Ptr() );
       
  3768 #endif
       
  3769     // Construct similar buffer than for version information and get po
       
  3770     HBufC* productInfo16 = versionInfo16->AllocLC();
       
  3771     TPtr productInfoptr16( productInfo16->Des() );
       
  3772 
       
  3773     // We assume that format from file is:
       
  3774     // SW version\ndate\nproduct\nmanufacturer
       
  3775     // \n is new line character
       
  3776 
       
  3777     // Find first new line character
       
  3778     index = versionInfo16->Locate( endLine );
       
  3779     if ( index >= 0 )
       
  3780         {
       
  3781         // Replace new line character using space.
       
  3782         versionInfoptr16[ index ] = KVtEngCharacterSpace ;
       
  3783 
       
  3784         // Find second new line character, this ends the version information
       
  3785         index = versionInfo16->Locate( endLine );
       
  3786         if ( index >= 0 )
       
  3787             {
       
  3788             // Take version information and ignore product info.
       
  3789             versionInfoptr16 = versionInfo16->Left( index );
       
  3790 
       
  3791             // Take product information and ignore version information.
       
  3792             productInfoptr16 = productInfo16->Mid( index + 1 );
       
  3793 
       
  3794             // Find the only remaining new line character.
       
  3795             index = productInfoptr16.Locate( endLine );
       
  3796 
       
  3797             // Replace new line character using space.
       
  3798             productInfoptr16[ index ] = KVtEngCharacterSpace;
       
  3799 
       
  3800             // Copy 16 bit descriptors to 8 bit descriptors and append
       
  3801             // zero terminators.
       
  3802             versionPtr8.Copy( versionInfoptr16 );
       
  3803             versionPtr8.ZeroTerminate();
       
  3804             productPtr8.Copy( productInfoptr16 );
       
  3805             productPtr8.ZeroTerminate();
       
  3806 
       
  3807             // Set the info to Protocol
       
  3808 #ifdef VTDEBUG
       
  3809             RDebug::Print(_L("MH.Product: %s" ), productPtr8.Ptr() );
       
  3810             RDebug::Print(_L("MH.Version: %s" ), versionPtr8.Ptr() );
       
  3811 #endif //VTDEBUG
       
  3812 
       
  3813             AddOperation( ESetVendorId,
       
  3814                 iH324Config->SetVendorId( KVtEngCountryCodeForProto,
       
  3815                 KVtEngExtensionForProto,
       
  3816                 KVtEngManufacturerForProto, &productPtr8, &versionPtr8 ) );
       
  3817             }
       
  3818         }
       
  3819     CleanupStack::PopAndDestroy( 4 ); // HBufC's
       
  3820     __VTPRINTEXIT( "MH.SetVersionInfoL" )
       
  3821     }
       
  3822 
       
  3823 
       
  3824 // -----------------------------------------------------------------------------
       
  3825 // CVtEngMediaHandler::RequestFrame
       
  3826 // -----------------------------------------------------------------------------
       
  3827 //
       
  3828 void CVtEngMediaHandler::RequestFrame( )
       
  3829     {
       
  3830     __VTPRINTENTER( "MH.RequestFrame" )
       
  3831     if ( !iH263Encoder )
       
  3832         {
       
  3833         __VTPRINT( DEBUG_MEDIA, "MH.RequestFrame FAILED")
       
  3834         return;
       
  3835         }
       
  3836     AddOperation( ESendIntraframe,iH263Encoder->RequestNextIntraFrame() );
       
  3837     ClearFlag( EProtoSendIntraFrame );
       
  3838 
       
  3839     __VTPRINTEXIT( "MH.RequestFrame" )
       
  3840     }
       
  3841 
       
  3842 // -----------------------------------------------------------------------------
       
  3843 // CVtEngMediaHandler::SetVideoQualityL
       
  3844 // -----------------------------------------------------------------------------
       
  3845 //
       
  3846 void CVtEngMediaHandler::SetVideoQualityL(
       
  3847     const TVideoQuality aVideoQuality, const TBool aSetPeerVideoQuality )
       
  3848     {
       
  3849     __VTPRINTENTER( "MH.SetVideoQualityL" )
       
  3850     if ( !iH263Encoder )
       
  3851         {
       
  3852         __VTPRINT( DEBUG_MEDIA, "MH.SetVideoQualityL FAILED")
       
  3853         return;
       
  3854         }
       
  3855     SetFlag( EVideoQualitySetByPeer );
       
  3856     TInt protoOperId( iH263Encoder->SetVideoFrameRate(
       
  3857         iVideoQuality.ToFrameRate( aVideoQuality ) ) );
       
  3858     AddOperation( ESetVideoQuality, protoOperId );
       
  3859     iVideoQuality.SettingVideoQuality( protoOperId,
       
  3860         aVideoQuality, aSetPeerVideoQuality );
       
  3861     __VTPRINTEXIT( "MH.SetVideoQualityL" )
       
  3862     }
       
  3863 
       
  3864 // -----------------------------------------------------------------------------
       
  3865 // CVtEngMediaHandler::SetPeerVideoQuality
       
  3866 // -----------------------------------------------------------------------------
       
  3867 //
       
  3868 void CVtEngMediaHandler::SetPeerVideoQuality( const TVideoQuality aVideoQuality )
       
  3869     {
       
  3870     __VTPRINTENTER( "MH.SetPeerVideoQuality" )
       
  3871     AddOperation( ESendVTSTO, iH324Config->SendVideoTemporalSpatialTradeoffCommand(
       
  3872         iVideoIncomingLogicalChannel.iLogicalChannelId,
       
  3873         iVideoQuality.ToTradeOff( aVideoQuality ) ) );
       
  3874     __VTPRINTEXIT( "MH.SetPeerVideoQuality" )
       
  3875     }
       
  3876 
       
  3877 // -----------------------------------------------------------------------------
       
  3878 // CVtEngMediaHandler::HandleVideoEncoderCommandCompletedL
       
  3879 // -----------------------------------------------------------------------------
       
  3880 //
       
  3881 void CVtEngMediaHandler::HandleVideoEncoderCommandCompletedL(
       
  3882     const TVtCommandResponse& aResponse )
       
  3883     {
       
  3884     __VTPRINTENTER( "MH.EncExtCommandCompleted" )
       
  3885     const TInt type( aResponse.iCmdType );
       
  3886     const TInt protoCmdId( aResponse.iCmdId );
       
  3887     const TInt protoResponse( aResponse.iCmdStatus );
       
  3888     __VTPRINT2( DEBUG_MEDIA, "MH.263 ComC type=%d", type )
       
  3889     __VTPRINT3( DEBUG_MEDIA, "MH.263 ComC cmdId=%d,response=%d",
       
  3890       protoCmdId, protoResponse )
       
  3891 
       
  3892     // Find correct entry in iPendingOps based on TOperation because there can
       
  3893     // be several entries with same Protocol cmd id since each Protocol interface has their
       
  3894     // own id allocation and ids may overlap.
       
  3895     TInt index( KErrNotFound );
       
  3896     TOperation completedOp = ENone;
       
  3897     if ( MatchResponseToPendingOps( protoCmdId, ESendIntraframe, &index ) ||
       
  3898          MatchResponseToPendingOps( protoCmdId, ESetIFrameInterval, &index ) ||
       
  3899          MatchResponseToPendingOps( protoCmdId, ESetVideoQuality, &index ) )
       
  3900         {
       
  3901         // TOperation entries in are unique in the array...
       
  3902         const TCmdOpPair pair = (*iPendingOps)[ index ];
       
  3903         completedOp = pair.iOp;
       
  3904         // ...so remove based on that instead of protoCmdId
       
  3905         RemoveOperation( completedOp );
       
  3906         }
       
  3907     else
       
  3908         {
       
  3909         __VTPRINT( DEBUG_MEDIA, "MH.EECC ERROR (response to unknown command)" )
       
  3910         }
       
  3911     if ( completedOp == ESetVideoQuality )
       
  3912         {
       
  3913         __VTPRINT( DEBUG_MEDIA, "MH.EECC ESetVideoQuality" )
       
  3914         if( iPendingOp && ( iPendingOp->Command() == KVtEngSetVideoQuality ) )
       
  3915             {
       
  3916             CompleteOp( protoResponse );
       
  3917             }
       
  3918         if( protoResponse == KErrNone )
       
  3919             {
       
  3920             TVtEngVideoQuality::TVQSParams vqp;
       
  3921 
       
  3922             if ( iVideoQuality.SettingSucceeded( protoCmdId, vqp ) )
       
  3923                 {
       
  3924                 __VTPRINT( DEBUG_MEDIA, "MH.EECC sending vq indication" )
       
  3925                 AddOperation( ESendVTSTO,
       
  3926                     iH324Config->SendVideoTemporalSpatialTradeoffIndication(
       
  3927                     iVideoOutgoingLogicalChannel.iLogicalChannelId,
       
  3928                     iVideoQuality.ToTradeOff( vqp.iValue ) ) );
       
  3929                 if ( vqp.iSetPeer )
       
  3930                     {
       
  3931                     __VTPRINT( DEBUG_MEDIA, "MH.EECC setting peer vq" )
       
  3932                     SetPeerVideoQuality( vqp.iValue );
       
  3933                     }
       
  3934                 }
       
  3935             }
       
  3936         else
       
  3937             {
       
  3938             iVideoQuality.SettingFailed( protoCmdId );
       
  3939             }
       
  3940         }
       
  3941     if ( iProtoState == MVtProtocolCommand::EIdle )
       
  3942         { // Command was complete during uninitialization.
       
  3943         NextUninitStepCallbackL();
       
  3944         }
       
  3945     __VTPRINTEXIT( "MH.EncExtCommandCompleted" )
       
  3946     }
       
  3947 
       
  3948 // -----------------------------------------------------------------------------
       
  3949 // CVtEngMediaHandler::HandleVideoEncoderInformationalEventL
       
  3950 // -----------------------------------------------------------------------------
       
  3951 //
       
  3952 void CVtEngMediaHandler::HandleVideoEncoderInformationalEventL(
       
  3953     const TVtIndicationEvent& aEvent)
       
  3954     {
       
  3955     const TInt type( aEvent.iEventType );
       
  3956     __VTPRINT2( DEBUG_MEDIA, "MH.263 infoevent=%d", type )
       
  3957     }
       
  3958 
       
  3959 // -----------------------------------------------------------------------------
       
  3960 // CVtEngMediaHandler::HandleH324MConfigCommandCompletedL
       
  3961 //
       
  3962 // -----------------------------------------------------------------------------
       
  3963 //
       
  3964 void CVtEngMediaHandler::HandleH324MConfigCommandCompletedL(
       
  3965     const TVtCommandResponse& aResponse )
       
  3966     {
       
  3967 	__VTPRINTENTER( "MH.HandleH324MConfigCommandCompletedL" )
       
  3968 	const TInt protoCmdId( aResponse.iCmdId );
       
  3969 	const TInt protoResponse( aResponse.iCmdStatus );
       
  3970 	const TInt type( aResponse.iCmdType );
       
  3971 
       
  3972 	__VTPRINT2( DEBUG_MEDIA, "MH.HandleH324MConfigCommandCompletedL type=%d", type )
       
  3973     __VTPRINT3( DEBUG_MEDIA, "MH.HandleH324MConfigCommandCompletedL cmdId=%d,response=%d", protoCmdId, protoResponse )
       
  3974     TInt index( KErrNotFound );
       
  3975     // Find correct entry in iPendingOps based on TOperation because there can
       
  3976     // be several entries with same Protocol cmd id since each Protocol interface has their
       
  3977     // own id allocation and ids may overlap.
       
  3978     if ( MatchResponseToPendingOps( protoCmdId, ESetVendorId, &index ) ||
       
  3979          MatchResponseToPendingOps( protoCmdId, ESendVTSTO, &index ) ||
       
  3980          MatchResponseToPendingOps( protoCmdId, ESetSupportedResolutions, &index ) ||
       
  3981          MatchResponseToPendingOps( protoCmdId, ESetFastCsupOptions, &index ) )
       
  3982         {
       
  3983         // TOperation entries in are unique in the array...
       
  3984         const TCmdOpPair pair = (*iPendingOps)[ index ];
       
  3985         // ...so remove based on that instead of protoCmdId
       
  3986         RemoveOperation( pair.iOp );
       
  3987         }
       
  3988     switch( iProtoState )
       
  3989         {
       
  3990         case MVtProtocolCommand::EConnected:
       
  3991             {
       
  3992         	CVtEngStateManager* stateManager = CVtEngUtility::StateManager();
       
  3993 
       
  3994         	// Check does the received command ID match to command ID that was received
       
  3995         	// from Protocol when DTMF was send.
       
  3996         	if( stateManager->Handlers().Dtmf().CheckCommandId( protoCmdId ) )
       
  3997         		{
       
  3998         		__VTPRINT( DEBUG_MEDIA, "MH.Complete DTMF" )
       
  3999         		stateManager->Handlers().Dtmf().SendComplete( protoResponse );
       
  4000         		}
       
  4001         	}
       
  4002             break;
       
  4003         case MVtProtocolCommand::EIdle: // extension command complete
       
  4004             NextUninitStepCallbackL();
       
  4005         default:
       
  4006             break;
       
  4007         }
       
  4008 
       
  4009 	__VTPRINTEXITR( "MH.HandleH324MConfigCommandCompletedL.CommandID %d", aResponse.iCmdId )
       
  4010     }
       
  4011 
       
  4012 // -----------------------------------------------------------------------------
       
  4013 // CVtEngMediaHandler::HandleH324MConfigInformationalEventL
       
  4014 //
       
  4015 // -----------------------------------------------------------------------------
       
  4016 //
       
  4017 void CVtEngMediaHandler::HandleH324MConfigInformationalEventL(
       
  4018     const TVtIndicationEvent& aEvent )
       
  4019     {
       
  4020 	__VTPRINTENTER( "MH.HandleH324MConfigInformationalEventL" )
       
  4021 
       
  4022 	const TInt type( aEvent.iEventType );
       
  4023 	const TUint8* buffer = (const_cast<TVtIndicationEvent&>(aEvent)).iLocalBuffer;
       
  4024 
       
  4025 	switch(type)
       
  4026 		{
       
  4027 		 case EVtIndicationVideoSpatialTamporalTradeOffIndication:
       
  4028 		 case EVtIndicationVideoSpatialTamporalTradeOffCommand:
       
  4029 			{
       
  4030 			TUint16 logicalChannelId = BigEndian::Get16( buffer );
       
  4031 			TUint8 tradeOffValue = buffer[ 2 ];
       
  4032 			__VTPRINT3( DEBUG_MEDIA, "MH.protoHIE.H324 channelId=%d, tradeOff=%d",
       
  4033 				logicalChannelId, tradeOffValue )
       
  4034 			if( type ==
       
  4035 				EVtIndicationVideoSpatialTamporalTradeOffIndication )
       
  4036 				{
       
  4037 				HandleSpatialTradeoffIndication( logicalChannelId,
       
  4038 					tradeOffValue );
       
  4039 				}
       
  4040 			else
       
  4041 				{
       
  4042 				HandleSpatialTradeoffCommandL( logicalChannelId,
       
  4043 					tradeOffValue );
       
  4044 				}
       
  4045 			}
       
  4046 			break;
       
  4047 
       
  4048 		// When remote terminal sends its UII capabilities in TCS we get
       
  4049 		// indication from Protocol. If remote does not send UII capas in TCS
       
  4050 		// we are obliged to use alphanumeric UIIs as specified by 245
       
  4051 		// spec. Default is IA5String.We get bit pattern from Protocol but
       
  4052 		// they are listed below in preferred order of usage.
       
  4053 		// The order can be freely chosen.
       
  4054 		case EVtIndicationUserInputCapability:
       
  4055 			{
       
  4056 #ifdef VTDEBUG
       
  4057 			RDebug::Print(_L("Buffer[0]:%d"), buffer[0] );
       
  4058 #endif // VTDEBUG
       
  4059 			__VTPRINT( DEBUG_MEDIA,
       
  4060 				"MH.protoHIE UserInput Capability Indication" )
       
  4061 
       
  4062 			CVtEngStateManager* stateManager =
       
  4063 				CVtEngUtility::StateManager();
       
  4064 
       
  4065 			// IA5String preferred, it's the simplest and most used in TCSs.
       
  4066 			if ( buffer[0] & CVtEngDtmfHandler::EIA5String )
       
  4067 				{
       
  4068 				stateManager->Handlers().Dtmf().SetUIISupport(
       
  4069 					CVtEngDtmfHandler::EIA5String );
       
  4070 				CVtEngEventManager::NotifyEvent(
       
  4071 					KVtEngRemoteUIIIA5StringSupport );
       
  4072 				__VTPRINT( DEBUG_MEDIA,
       
  4073 					"KVtEngRemoteUIIIA5StringSupport Support signalled" )
       
  4074 				}
       
  4075 			// Basic string is also simple and easy to use, second position.
       
  4076 			else if ( buffer[0] & CVtEngDtmfHandler::EBasicString )
       
  4077 				{
       
  4078 				stateManager->Handlers().Dtmf().SetUIISupport(
       
  4079 					CVtEngDtmfHandler::EBasicString );
       
  4080 				CVtEngEventManager::NotifyEvent(
       
  4081 					KVtEngRemoteUIIBasicStringSupport );
       
  4082 				__VTPRINT( DEBUG_MEDIA,
       
  4083 					"KVtEngRemoteUIIBasicStringSupport Support signalled" )
       
  4084 				}
       
  4085 			// DTMFs are more limited but more interoperable than
       
  4086 			// General string.
       
  4087 			else if ( buffer[0] & CVtEngDtmfHandler::EDTMFString )
       
  4088 				{
       
  4089 				stateManager->Handlers().Dtmf().SetUIISupport(
       
  4090 					CVtEngDtmfHandler::EDTMFString );
       
  4091 				CVtEngEventManager::NotifyEvent( KVtEngRemoteUIIDtmfSupport );
       
  4092 				__VTPRINT( DEBUG_MEDIA,
       
  4093 					"KVtEngRemoteUIIDtmfSupport Support signalled" )
       
  4094 				}
       
  4095 			// General string is the complicated one, priority is
       
  4096 			// lowest because of possible diffuculties in remote
       
  4097 			// end decoding of string (various number of letter
       
  4098 			// combinations).
       
  4099 			else if ( buffer[0] & CVtEngDtmfHandler::EGeneralString )
       
  4100 				{
       
  4101 				stateManager->Handlers().Dtmf().SetUIISupport(
       
  4102 					CVtEngDtmfHandler::EGeneralString );
       
  4103 				CVtEngEventManager::NotifyEvent(
       
  4104 					KVtEngRemoteUIIGeneralStringSupport );
       
  4105 				__VTPRINT( DEBUG_MEDIA,
       
  4106 					"KVtEngRemoteUIIGeneralStringSupport Support signalled" )
       
  4107 				}
       
  4108 			else
       
  4109 				{
       
  4110 				__VTPRINT( DEBUG_MEDIA, "MH.HIE invalid DTMF" )
       
  4111 				Panic( EVtEngPanicInvalidDtmfState );
       
  4112 				}
       
  4113 			}
       
  4114 			break;
       
  4115 		}
       
  4116 	__VTPRINTEXIT( "MH.HandleH324MConfigInformationalEventL" )
       
  4117     }
       
  4118 
       
  4119 // -----------------------------------------------------------------------------
       
  4120 // CVtEngMediaHandler::SetSupportedResolutionsL
       
  4121 // Sets supported resolutions to protocol.
       
  4122 // -----------------------------------------------------------------------------
       
  4123 //
       
  4124 void CVtEngMediaHandler::SetSupportedResolutions()
       
  4125     {
       
  4126     __VTPRINTENTER( "MH.SetSupportedResolutions" )
       
  4127     __ASSERT_ALWAYS( iH324Config != NULL, Panic( EVtEngPanicInvalidPointer ) );
       
  4128 
       
  4129      AddOperation( ESetSupportedResolutions,
       
  4130             iH324Config->SetSupportedResolutions( ) );
       
  4131     __VTPRINTEXIT( "MH.SetSupportedResolutions " )
       
  4132     }
       
  4133 
       
  4134 // -----------------------------------------------------------------------------
       
  4135 // CVtEngMediaHandler::SetFastCsupOptions
       
  4136 // Sets supported resolutions to Protocol.
       
  4137 // -----------------------------------------------------------------------------
       
  4138 //
       
  4139 void CVtEngMediaHandler::SetFastCsupOptions()
       
  4140 	{
       
  4141 	__VTPRINTENTER( "MH.SetFastCsupOptions" )
       
  4142 	
       
  4143     AddOperation(
       
  4144         ESetFastCsupOptions,
       
  4145         iH324Config->SetFastCsupOptions( ) );
       
  4146     __VTPRINTEXIT( "MH.SetFastCsupOptions" )
       
  4147 	}
       
  4148 
       
  4149 // -----------------------------------------------------------------------------
       
  4150 // CVtEngMediaHandler::CreateExtensionsL
       
  4151 // Creates extension according to API Uid.
       
  4152 // -----------------------------------------------------------------------------
       
  4153 //
       
  4154 CVtEngExtensionBase* CVtEngMediaHandler::CreateExtensionsL( const TUid& aUid )
       
  4155     {
       
  4156     __VTPRINTENTER( "MH.CreateExtensionsL" )
       
  4157 
       
  4158     // if UID is supported camera pref
       
  4159     if ( aUid == KVtEngExtensionCameraPreferences )
       
  4160     	{
       
  4161     	__VTPRINT2( DEBUG_GEN, "MH.CreateExtensionsL extension UID=%d",
       
  4162     		aUid.iUid )
       
  4163 
       
  4164     	CVtEngExtensionBase* base = reinterpret_cast< CVtEngExtensionBase* >
       
  4165     		( iLocalVideo->CreateCameraPreferencesL() );
       
  4166     	__VTPRINTEXITR( "MH.CreateExtensionsL base [%d]", ( TInt )base )
       
  4167         return base;
       
  4168     	}
       
  4169 
       
  4170 #if defined ( RD_VT_RTF )
       
  4171 
       
  4172     // if UID is supported R2F
       
  4173     else if ( aUid == KVtEngExtensionRecord2File )
       
  4174     	{
       
  4175     	 CVtEngExtensionBase* base = reinterpret_cast< CVtEngExtensionBase* >
       
  4176     		( CVtEngRecord2File::NewL() );
       
  4177     	__VTPRINTEXITR( "MH.CreateExtensionsL base [%d]", ( TInt )base )
       
  4178         return base;
       
  4179     	}
       
  4180     // not supported UID
       
  4181 
       
  4182 #endif //RD_VT_RTF
       
  4183 
       
  4184     else
       
  4185     	{
       
  4186     	__VTPRINTEXITR( "MH.CreateExtensionsL error [%d]", KErrNotSupported )
       
  4187     	User::Leave( KErrNotSupported);
       
  4188     	return NULL;
       
  4189     	}
       
  4190     }
       
  4191 
       
  4192 // Implementation for TVtEngVideoQuality
       
  4193 
       
  4194 // -----------------------------------------------------------------------------
       
  4195 // CVtEngMediaHandler::TVtEngVideoQuality::TVtEngVideoQuality
       
  4196 // -----------------------------------------------------------------------------
       
  4197 //
       
  4198 CVtEngMediaHandler::TVtEngVideoQuality::TVtEngVideoQuality()
       
  4199     : iCurrent( EVideoQualityNormal ), iParamList( 1 )
       
  4200     {
       
  4201     }
       
  4202 
       
  4203 // -----------------------------------------------------------------------------
       
  4204 // CVtEngMediaHandler::TVtEngVideoQuality::~TVtEngVideoQuality
       
  4205 // -----------------------------------------------------------------------------
       
  4206 //
       
  4207 CVtEngMediaHandler::TVtEngVideoQuality::~TVtEngVideoQuality()
       
  4208     {
       
  4209     iParamList.Reset();
       
  4210     }
       
  4211 
       
  4212 // -----------------------------------------------------------------------------
       
  4213 // CVtEngMediaHandler::TVtEngVideoQuality::SettingVideoQuality
       
  4214 // -----------------------------------------------------------------------------
       
  4215 //
       
  4216 void CVtEngMediaHandler::TVtEngVideoQuality::SettingVideoQuality(
       
  4217     TInt aId, const TVideoQuality aValue, TBool aSetPeer )
       
  4218     {
       
  4219     __VTPRINTENTER( "MH.VQ.SettingVideoQuality" )
       
  4220     iParamList.Append( TVQSParams( aId, aValue, aSetPeer ) );
       
  4221     __VTPRINTEXIT( "MH.VQ.SettingVideoQuality" )
       
  4222     }
       
  4223 
       
  4224 // -----------------------------------------------------------------------------
       
  4225 // CVtEngMediaHandler::TVtEngVideoQuality::VideoQuality
       
  4226 // -----------------------------------------------------------------------------
       
  4227 //
       
  4228 MVtEngMedia::TVideoQuality
       
  4229     CVtEngMediaHandler::TVtEngVideoQuality::VideoQuality() const
       
  4230     {
       
  4231     __VTPRINTENTER( "MH.VQ.VideoQuality" )
       
  4232     __VTPRINTEXITR( "MH.VQ.VideoQuality %d", iCurrent )
       
  4233     return iCurrent;
       
  4234     }
       
  4235 
       
  4236 // -----------------------------------------------------------------------------
       
  4237 // CVtEngMediaHandler::TVtEngVideoQuality::IsSetPeer
       
  4238 // -----------------------------------------------------------------------------
       
  4239 //
       
  4240 TBool CVtEngMediaHandler::TVtEngVideoQuality::SettingSucceeded( TInt aId,
       
  4241     TVQSParams& aParams )
       
  4242     {
       
  4243     __VTPRINTENTER( "MH.VQ.SettingSucceeded" )
       
  4244     TInt index( FindVQSParam( aId ) );
       
  4245     TBool foundRecord( index != KErrNotFound );
       
  4246     if ( foundRecord )
       
  4247         {
       
  4248         aParams = iParamList[ index ];
       
  4249         iParamList.Remove( index );
       
  4250         iParamList.Compress();
       
  4251         }
       
  4252     __VTPRINTEXITR( "MH.VQ.SettingSucceeded %d", foundRecord )
       
  4253     return foundRecord;
       
  4254     }
       
  4255 
       
  4256 // -----------------------------------------------------------------------------
       
  4257 // CVtEngMediaHandler::TVtEngVideoQuality::IsSetPeer
       
  4258 // -----------------------------------------------------------------------------
       
  4259 //
       
  4260 void CVtEngMediaHandler::TVtEngVideoQuality::UpdateVideoQuality(
       
  4261     const TVideoQuality aVideoQuality )
       
  4262     {
       
  4263     __VTPRINTENTER( "MH.VQ.UpdateVideoQuality" )
       
  4264     iCurrent = aVideoQuality;
       
  4265     __VTPRINTEXIT( "MH.VQ.UpdateVideoQuality" )
       
  4266     }
       
  4267 
       
  4268 // -----------------------------------------------------------------------------
       
  4269 // CVtEngMediaHandler::TVtEngVideoQuality::SettingFailed
       
  4270 // -----------------------------------------------------------------------------
       
  4271 //
       
  4272 void CVtEngMediaHandler::TVtEngVideoQuality::SettingFailed( TInt aId )
       
  4273     {
       
  4274     __VTPRINTENTER( "MH.VQ.SettingFailed" )
       
  4275     TInt index( FindVQSParam( aId ) );
       
  4276     if ( index != KErrNotFound )
       
  4277         {
       
  4278         iParamList.Remove( index );
       
  4279         iParamList.Compress();
       
  4280         }
       
  4281     __VTPRINTEXITR( "MH.VQ.SettingFailed %d", index )
       
  4282     }
       
  4283 
       
  4284 // -----------------------------------------------------------------------------
       
  4285 // CVtEngMediaHandler::TVtEngVideoQuality::FromTradeOff
       
  4286 // -----------------------------------------------------------------------------
       
  4287 //
       
  4288 MVtEngMedia::TVideoQuality
       
  4289     CVtEngMediaHandler::TVtEngVideoQuality::FromTradeOff(
       
  4290     const TInt aTradeOff ) const
       
  4291     {
       
  4292     __VTPRINTENTER( "MH.VQ.FromTradeOff" )
       
  4293     TVideoQuality videoQuality;
       
  4294 
       
  4295     // [0 .. KVtEngTradeOffDetailMax]
       
  4296     if( aTradeOff <= KVtEngTradeOffDetailMax )
       
  4297         {
       
  4298         videoQuality = EVideoQualityDetail;
       
  4299         }
       
  4300     // ]KVtEngTradeOffDetailMax .. KVtEngTradeOffNormalMax]
       
  4301     else if( aTradeOff <= KVtEngTradeOffNormalMax )
       
  4302         {
       
  4303         videoQuality = EVideoQualityNormal;
       
  4304         }
       
  4305     // ]KVtEngTradeOffNormalMax .. 31]
       
  4306     else
       
  4307         {
       
  4308         videoQuality = EVideoQualityMotion;
       
  4309         }
       
  4310     __VTPRINTEXITR( "MH.VQ.FromTradeOff %d", videoQuality )
       
  4311     return videoQuality;
       
  4312     }
       
  4313 
       
  4314 // -----------------------------------------------------------------------------
       
  4315 // CVtEngMediaHandler::TVtEngVideoQuality::ToFrameRate
       
  4316 // -----------------------------------------------------------------------------
       
  4317 //
       
  4318 TInt CVtEngMediaHandler::TVtEngVideoQuality::ToFrameRate(
       
  4319     const TVideoQuality aVideoQuality ) const
       
  4320     {
       
  4321     __VTPRINTENTER( "MH.VQ.ToFrameRate" )
       
  4322     TInt frameRate( 0 );
       
  4323     CVtEngSettings& settings = CVtEngUtility::Settings();
       
  4324     switch( aVideoQuality )
       
  4325         {
       
  4326         case EVideoQualityDetail:
       
  4327             frameRate = settings.VideoQualityFrameRateConfig().iDetail;
       
  4328             break;
       
  4329 
       
  4330         case EVideoQualityNormal:
       
  4331             frameRate = settings.VideoQualityFrameRateConfig().iNormal;
       
  4332             break;
       
  4333 
       
  4334         case EVideoQualityMotion:
       
  4335             frameRate = settings.VideoQualityFrameRateConfig().iMotion;
       
  4336             break;
       
  4337 
       
  4338         default:
       
  4339             Panic( EVtEngPanicInvalidVideoQualityValue );
       
  4340             break;
       
  4341         }
       
  4342     __VTPRINTEXITR( "MH.VQ.ToFrameRate %d", frameRate )
       
  4343     return frameRate;
       
  4344     }
       
  4345 
       
  4346 // -----------------------------------------------------------------------------
       
  4347 // CVtEngMediaHandler::TVtEngVideoQuality::ToTradeOff
       
  4348 // -----------------------------------------------------------------------------
       
  4349 //
       
  4350 TUint8 CVtEngMediaHandler::TVtEngVideoQuality::ToTradeOff(
       
  4351     const TVideoQuality aVideoQuality ) const
       
  4352     {
       
  4353     __VTPRINTENTER( "MH.VQ.ToTradeOff" )
       
  4354     TUint8 tradeOff( 0 );
       
  4355     switch( aVideoQuality )
       
  4356         {
       
  4357         case EVideoQualityDetail:
       
  4358             tradeOff = KVtEngTradeOffDetailMax;
       
  4359             break;
       
  4360 
       
  4361         case EVideoQualityNormal:
       
  4362             tradeOff = KVtEngTradeOffNormalMax;
       
  4363             break;
       
  4364 
       
  4365         case EVideoQualityMotion:
       
  4366             tradeOff = KVtEngTradeOffMotionMax;
       
  4367             break;
       
  4368 
       
  4369         default:
       
  4370             Panic( EVtEngPanicInvalidVideoQualityValue );
       
  4371             break;
       
  4372         }
       
  4373     __VTPRINTEXITR( "MH.VQ.ToTradeOff %d", tradeOff )
       
  4374     return tradeOff;
       
  4375     }
       
  4376 
       
  4377 // -----------------------------------------------------------------------------
       
  4378 // CVtEngMediaHandler::TVtEngVideoQuality::FindVQSParam
       
  4379 // -----------------------------------------------------------------------------
       
  4380 //
       
  4381 TInt CVtEngMediaHandler::TVtEngVideoQuality::FindVQSParam( TInt aId ) const
       
  4382     {
       
  4383     __VTPRINTENTER( "MH.VQ.FindVQSParam" )
       
  4384     TInt result( KErrNotFound );
       
  4385     for ( TInt i = iParamList.Count() - 1; i >= 0; i-- )
       
  4386         {
       
  4387         if ( iParamList[ i ].iId == aId )
       
  4388             {
       
  4389             result = i;
       
  4390             break;
       
  4391             }
       
  4392         }
       
  4393     __VTPRINTEXITR( "MH.VQ.FindVQSParam %d", result )
       
  4394     return result;
       
  4395     }
       
  4396 
       
  4397 // -----------------------------------------------------------------------------
       
  4398 // CVtEngMediaHandler::TVtEngVideoQuality::TVQSParams::TVQSParams
       
  4399 // -----------------------------------------------------------------------------
       
  4400 //
       
  4401 CVtEngMediaHandler::TVtEngVideoQuality::TVQSParams::TVQSParams()
       
  4402     {
       
  4403     Mem::FillZ( this, sizeof( TVQSParams ) );
       
  4404     }
       
  4405 
       
  4406 // -----------------------------------------------------------------------------
       
  4407 // CVtEngMediaHandler::TVtEngVideoQuality::TVQSParams::TVQSParams
       
  4408 // -----------------------------------------------------------------------------
       
  4409 //
       
  4410 CVtEngMediaHandler::TVtEngVideoQuality::TVQSParams::TVQSParams(
       
  4411     TInt aId, const TVideoQuality aValue, TBool aSetPeer )
       
  4412     : iId( aId ), iValue( aValue ), iSetPeer( aSetPeer )
       
  4413     {
       
  4414     }
       
  4415 
       
  4416 // -----------------------------------------------------------------------------
       
  4417 // CVtEngMediaHandler::QueryProtoInterfacesL
       
  4418 // -----------------------------------------------------------------------------
       
  4419 //
       
  4420 void CVtEngMediaHandler::QueryProtoInterfacesL()
       
  4421 	{
       
  4422 	__VTPRINTENTER( "MH.QueryProtoInterfacesL" )
       
  4423 	// Ensure call is still connected to prevent unnecessary Protocol
       
  4424 	// interface acquisition
       
  4425     CVtEngStateManager* states = CVtEngUtility::StateManager();
       
  4426 	const MVtEngSessionInfo::TSessionState sessionState =
       
  4427 	    states->SessionState();
       
  4428       if ( sessionState != MVtEngSessionInfo::EIdle &&
       
  4429 	       sessionState != MVtEngSessionInfo::EClearing )
       
  4430 
       
  4431         {
       
  4432     	// Request the 324M Stack interface
       
  4433     	if ( !IsFlag( EProto324IFAcquired ) )
       
  4434     		{
       
  4435     		/*
       
  4436     		AddOperation( EGet324CtrlInterface,
       
  4437     			iSessionCommand->GetProtocolInterfaceL(
       
  4438     				EVtH324Config,
       
  4439     				( MVtProtocolCommand*& ) iH324Config ));
       
  4440     				*/
       
  4441     		MVtProtocolCommand *pCommand = NULL;
       
  4442     		AddOperation( EGet324CtrlInterface,
       
  4443     		    iSessionCommand->GetProtocolInterfaceL(
       
  4444     		        EVtH324Config,
       
  4445     		        ( MVtProtocolCommand*& ) pCommand ));           
       
  4446     		iH324Config = static_cast<MVtH324ConfigCommand *>(pCommand);
       
  4447     		}
       
  4448     	// Get encoder interface.
       
  4449     	/*
       
  4450     	AddOperation( EGetH263EncInterface,
       
  4451     		iSessionCommand->GetProtocolInterfaceL(
       
  4452     			EVtVideoEncoderConfig,
       
  4453     			( MVtProtocolCommand*& ) iH263Encoder ));
       
  4454     			*/
       
  4455     	MVtProtocolCommand *pCommand = NULL;
       
  4456     	AddOperation( EGetH263EncInterface,
       
  4457     	    iSessionCommand->GetProtocolInterfaceL(
       
  4458     	        EVtVideoEncoderConfig,
       
  4459     	        ( MVtProtocolCommand*& ) pCommand ));       
       
  4460     	iH263Encoder = static_cast<MVtVideoConfigCommand *>(pCommand);
       
  4461         }
       
  4462 	__VTPRINTEXIT( "MH.QueryProtoInterfacesL" )
       
  4463 	}
       
  4464 
       
  4465 // -----------------------------------------------------------------------------
       
  4466 // CVtEngMediaHandler::ReleaseProtoInterfacesL
       
  4467 // -----------------------------------------------------------------------------
       
  4468 //
       
  4469 void CVtEngMediaHandler::ReleaseProtoInterfacesL()
       
  4470 	{
       
  4471 	__VTPRINTENTER( "MH.ReleaseProtoInterfacesL" )
       
  4472 
       
  4473 	// Release interfaces
       
  4474 	__VTPRINT( DEBUG_MEDIA, "LCN: MH.324 started to release interfaces" )
       
  4475 	if( iH324Config )
       
  4476 		{
       
  4477 		/*
       
  4478 		AddOperation( ERemove324CtrlInterface,
       
  4479         iSessionCommand->DeleteProtocolInterfaceL( EVtH324Config, iH324Config ) );*/
       
  4480 		MVtProtocolCommand *pCommand = NULL;
       
  4481 		pCommand = static_cast<MVtProtocolCommand *>(iH324Config);
       
  4482 		AddOperation( ERemove324CtrlInterface,
       
  4483 		        iSessionCommand->DeleteProtocolInterfaceL( EVtH324Config, pCommand ) );     
       
  4484         iH324Config = 0;
       
  4485 		__VTPRINT( DEBUG_MEDIA, "MH.324 started to release" )
       
  4486         }
       
  4487 
       
  4488     if ( iH263Encoder )
       
  4489         {
       
  4490         /*
       
  4491 		AddOperation( ERemoveH263EncInterface,
       
  4492         iSessionCommand->DeleteProtocolInterfaceL( EVtVideoEncoderConfig, iH263Encoder ) );*/
       
  4493         MVtProtocolCommand *pCommand = NULL;
       
  4494         pCommand = static_cast<MVtProtocolCommand *>(iH263Encoder);
       
  4495         AddOperation( ERemoveH263EncInterface,
       
  4496                 iSessionCommand->DeleteProtocolInterfaceL( EVtVideoEncoderConfig, pCommand ) );        
       
  4497                 iH263Encoder = 0;
       
  4498 		iH263Encoder = 0;
       
  4499         __VTPRINT( DEBUG_MEDIA, "MH.263 started to release" )
       
  4500         }
       
  4501 	__VTPRINTEXIT( "MH.ReleaseProtoInterfacesL" )
       
  4502 	}
       
  4503 
       
  4504 // -----------------------------------------------------------------------------
       
  4505 // CVtEngMediaHandler::ExtensionCommandsPending
       
  4506 // -----------------------------------------------------------------------------
       
  4507 //
       
  4508 TBool CVtEngMediaHandler::ExtensionCommandsPending() const
       
  4509     {
       
  4510     __VTPRINTENTER( "MH.ExtensionCommandsPending" )
       
  4511     TBool isPending = EFalse;
       
  4512     TInt count( iPendingOps->Count() );
       
  4513     while ( count-- )
       
  4514         {
       
  4515         const TOperation op = ( *iPendingOps )[ count ].iOp;
       
  4516         switch ( op )
       
  4517             {
       
  4518             // extension commands
       
  4519             case ESendIntraframe:
       
  4520             case ESetSupportedResolutions:
       
  4521             case ESetVideoQuality:
       
  4522 			case ESendVTSTO:
       
  4523             case ESetFastCsupOptions:
       
  4524             case ESetVendorId:
       
  4525             case ESetIFrameInterval:
       
  4526                 isPending = ETrue;
       
  4527 #ifdef _DEBUG
       
  4528                 RDebug::Print( _L("  (ext) op=%d,protoCmdId=%d"),
       
  4529                     op, ( *iPendingOps )[ count ].iProtoCmdId );
       
  4530 #else
       
  4531 // in debug mode allow printing all pending ops to log
       
  4532                 count = 0; // break loop
       
  4533 #endif
       
  4534                 break;
       
  4535             default:
       
  4536                 break;
       
  4537             }
       
  4538         }
       
  4539     __VTPRINTEXITR( "MH.ExtensionCommandsPending %d", isPending )
       
  4540     return isPending;
       
  4541     }
       
  4542 
       
  4543 // -----------------------------------------------------------------------------
       
  4544 // CVtEngMediaHandler::MediaAddingValidity
       
  4545 // -----------------------------------------------------------------------------
       
  4546 //
       
  4547 TBool CVtEngMediaHandler::MediaAddingValidity() const
       
  4548     {
       
  4549     __VTPRINTENTER( "MH.MediaAddingValidity" )
       
  4550 
       
  4551     TBool addingOK( ETrue );
       
  4552     CVtEngStateManager* states = CVtEngUtility::StateManager();
       
  4553     MVtEngSessionInfo::TSessionState sessionState ( states->SessionState() );
       
  4554     if( sessionState == MVtEngSessionInfo::EClearing ||
       
  4555         sessionState == MVtEngSessionInfo::EIdle )
       
  4556         {
       
  4557         __VTPRINT( DEBUG_MEDIA, "MH.MediaAddingValidity NOT ALLOWED" )
       
  4558         // State is wrong, adding not allowed.
       
  4559         addingOK = EFalse;
       
  4560         }
       
  4561 
       
  4562     __VTPRINTEXITR( "MH.MediaAddingValidity %d", addingOK )
       
  4563 
       
  4564     return addingOK;
       
  4565     }
       
  4566 
       
  4567 // -----------------------------------------------------------------------------
       
  4568 // CVtEngMediaHandler::CancelInitializeShareImage
       
  4569 // -----------------------------------------------------------------------------
       
  4570 void CVtEngMediaHandler::CancelInitializeShareImage()
       
  4571     {
       
  4572     __VTPRINTENTER( "CVtEngMediaHandler.CancelInitializeShareImage");
       
  4573     if(iLocalVideo)
       
  4574         {
       
  4575         iLocalVideo->CancelInitializeShareImage();
       
  4576         }
       
  4577     __VTPRINTEXIT( "CVtEngMediaHandler.CancelInitializeShareImage");
       
  4578     }
       
  4579 
       
  4580 //  End of File