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