vtengines/videoteleng/Src/Media/CVtEngRemoteVideo.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2004-2006 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:  Remote video handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CVtEngRemoteVideo.h"
       
    22 #include    "CVtEngStateManager.h"
       
    23 #include    "MVtEngFrameObserver.h"
       
    24 #include    <videotelephonyvariant.hrh>
       
    25 #include    "CVtEngSettings.h"
       
    26 #include    "VtEngUtils.h"
       
    27 #include    "CVtEngEventManager.h"
       
    28 #include    "VtEngConstants.h"
       
    29 #include    "VtEngPanic.h"
       
    30 #include    "TVtEngRenderingDSA.h"
       
    31 #include    "TVtEngRenderingDP.h"
       
    32 #include    "TVtEngRenderingNGA.h"
       
    33 #include    "TVtEngRenderConfigDSA.h"
       
    34 #include    "TVtEngRenderConfigDP.h"
       
    35 #include    "TVtEngRenderConfigNGA.h"
       
    36 #include    "CVtEngDrawDP.h"
       
    37 #include    "CVtEngDrawDSA.h"
       
    38 #include    "CVtEngDrawNGA.h"
       
    39 #include    <fbs.h>
       
    40 #include    <w32std.h>
       
    41 #include    <cvtlogger.h>
       
    42 #include    <mvtprotocolhandler.h>
       
    43 #include    <featmgr.h>
       
    44 
       
    45 // LOCAL CONSTANTS AND MACROS
       
    46 // This active object priority.
       
    47 const TInt KVtEngRemoteDrawPriority = CActive::EPriorityStandard;
       
    48 
       
    49 // Timer priority when not frame watching.
       
    50 const TInt KVtEngStoppedRenderPriority = CActive::EPriorityLow;
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CVtEngRemoteVideo::CVtEngRemoteVideo
       
    56 // C++ constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CVtEngRemoteVideo::CVtEngRemoteVideo(
       
    61     MVtSessionCommand& aSessionCommand,
       
    62     CVtEngStateManager& aStateManager ) :
       
    63     iSessionCommand( aSessionCommand),
       
    64     iStateManager( aStateManager ),
       
    65     iEnableNGA(ETrue)
       
    66     {
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CVtEngRemoteVideo::ConstructL
       
    71 // Symbian 2nd phase constructor can leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CVtEngRemoteVideo::ConstructL()
       
    75     {
       
    76     __VTPRINTENTER( "RV.ConstructL" )
       
    77     //We are in the Proto ESetup state
       
    78     iDrawer =
       
    79         static_cast< CVtEngDraw* >( VtEngDrawFactory::CreateDrawerL( this , iEnableNGA) );
       
    80     //Add protocol Data Sink;
       
    81     iDisplaySink = iDrawer->DisplaySink();
       
    82     iAudioSink = VTProtocolFactory::CreateAudioSink();
       
    83     __VTPRINTEXIT( "RV.ConstructL" )
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CVtEngRemoteVideo::NewL
       
    88 // Two-phased constructor.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CVtEngRemoteVideo* CVtEngRemoteVideo::NewL(
       
    92     MVtSessionCommand& aSessionCommand,
       
    93     CVtEngStateManager& aStateManager )
       
    94     {
       
    95     CVtEngRemoteVideo* self = new( ELeave )
       
    96         CVtEngRemoteVideo( aSessionCommand, aStateManager );
       
    97     CleanupStack::PushL( self );
       
    98     self->ConstructL();
       
    99     CleanupStack::Pop();
       
   100     return self;
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CVtEngRemoteVideo::CVtEngRemoteVideo
       
   105 // Destructor. Cannot leave.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CVtEngRemoteVideo::~CVtEngRemoteVideo()
       
   109     {
       
   110     __VTPRINTENTER( "RV.~" )
       
   111 	VTProtocolFactory::DeleteAudioSink( iAudioSink );
       
   112     delete iDrawer;
       
   113     __VTPRINTEXIT( "RV.~" )
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CVtEngRemoteVideo::SetRenderingParametersL
       
   118 // Sets parameters for rendering the remote video.
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CVtEngRemoteVideo::SetRenderingParametersL(
       
   122     const TVtEngRenderingOptionsNGA& aParams )
       
   123     {
       
   124     __VTPRINTENTER( "RV.SetRenderingParametersL NGA" )
       
   125         
       
   126     // If rendering is ongoing, stop it
       
   127     StopVideoRendering();
       
   128     // Set new values
       
   129     TVtEngRenderConfigNGA config( aParams );
       
   130     iDrawer->BaseSetConfigL( config );
       
   131     __VTPRINTEXIT( "RV.SetRenderingParametersL NGA" )
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CVtEngRemoteVideo::SetRenderingParametersL
       
   136 // Sets parameters for rendering the remote video.
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CVtEngRemoteVideo::SetRenderingParametersL(
       
   140     const TVtEngRenderingOptionsDSA& aParams )
       
   141     {
       
   142     __VTPRINTENTER( "RV.SetRenderingParametersL DSA" )
       
   143 
       
   144     __VTPRINT( DEBUG_MEDIA , "================== RV.Params ==================" )
       
   145     __VTPRINT2( DEBUG_MEDIA , "    aParams.iRect.iTl.iX %d", aParams.iRect.iTl.iX )
       
   146     __VTPRINT2( DEBUG_MEDIA , "    aParams.iRect.iTl.iY %d", aParams.iRect.iTl.iY )
       
   147     __VTPRINT2( DEBUG_MEDIA , "    aParams.iRect.iBr.iX %d", aParams.iRect.iBr.iX )
       
   148     __VTPRINT2( DEBUG_MEDIA , "    aParams.iRect.iBr.iY %d", aParams.iRect.iBr.iY )
       
   149     __VTPRINT2( DEBUG_MEDIA , "    aParams.iClipRect.iTl.iX %d",
       
   150         aParams.iClipRect.iTl.iX )
       
   151     __VTPRINT2( DEBUG_MEDIA , "    aParams.iClipRect.iTl.iY %d",
       
   152         aParams.iClipRect.iTl.iY )
       
   153     __VTPRINT2( DEBUG_MEDIA , "    aParams.iClipRect.iBr.iX %d",
       
   154         aParams.iClipRect.iBr.iX )
       
   155     __VTPRINT2( DEBUG_MEDIA , "    aParams.iClipRect.iBr.iY %d",
       
   156         aParams.iClipRect.iBr.iY )
       
   157     __VTPRINT( DEBUG_MEDIA , "================== RV.Params ==================" )
       
   158     // If rendering is ongoing, stop it
       
   159     StopVideoRendering();
       
   160     // Set new values
       
   161     TVtEngRenderConfigDSA config( aParams );
       
   162     iDrawer->BaseSetConfigL( config );
       
   163     __VTPRINTEXIT( "RV.SetRenderingParametersL DSA" )
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CVtEngRemoteVideo::SetRenderingParametersL
       
   168 // Sets parameters for rendering the remote video.
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CVtEngRemoteVideo::SetRenderingParametersL(
       
   172     const TVtEngRenderingOptionsDP& aParams )
       
   173     {
       
   174     __VTPRINTENTER( "RV.SetRenderingParametersL DP" )
       
   175 
       
   176     __VTPRINT( DEBUG_MEDIA , "================== RV.Params ==================" )
       
   177     __VTPRINT2( DEBUG_MEDIA , "    aParams.iRect.iTl.iX %d", aParams.iRect.iTl.iX )
       
   178     __VTPRINT2( DEBUG_MEDIA , "    aParams.iRect.iTl.iY %d", aParams.iRect.iTl.iY )
       
   179     __VTPRINT2( DEBUG_MEDIA , "    aParams.iRect.iBr.iX %d", aParams.iRect.iBr.iX )
       
   180     __VTPRINT2( DEBUG_MEDIA , "    aParams.iRect.iBr.iY %d", aParams.iRect.iBr.iY )
       
   181     __VTPRINT2( DEBUG_MEDIA , "    aParams.iClipRect.iTl.iX %d",
       
   182         aParams.iClipRect.iTl.iX )
       
   183     __VTPRINT2( DEBUG_MEDIA , "    aParams.iClipRect.iTl.iY %d",
       
   184         aParams.iClipRect.iTl.iY )
       
   185     __VTPRINT2( DEBUG_MEDIA , "    aParams.iClipRect.iBr.iX %d",
       
   186         aParams.iClipRect.iBr.iX )
       
   187     __VTPRINT2( DEBUG_MEDIA , "    aParams.iClipRect.iBr.iY %d",
       
   188         aParams.iClipRect.iBr.iY )
       
   189     __VTPRINT( DEBUG_MEDIA , "================== RV.Params ==================" )
       
   190     // If rendering is ongoing, stop it
       
   191     StopVideoRendering();
       
   192     // Set new values
       
   193     TVtEngRenderConfigDP config( aParams );
       
   194     iDrawer->BaseSetConfigL( config );
       
   195     __VTPRINTEXIT( "RV.SetRenderingParametersL DP" )
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CVtEngRemoteVideo::StartVideoL
       
   200 //
       
   201 // For incoming, this function starts/resumes playing out the media to the
       
   202 // appropriate sink based on the current settings.
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CVtEngRemoteVideo::StartVideoL()
       
   206     {
       
   207     __VTPRINTENTER( "RV.StartVideoL" )
       
   208     if ( iDisplaySink && iDrawer &&
       
   209          ( iDrawer->IsFlag( CVtEngDraw::EFlagInitialized ) ||
       
   210            iDrawer->IsFlag( CVtEngDraw::EBaseConstructCalled ) ) )
       
   211         {
       
   212         iDrawer->BaseStartDrawL();
       
   213         }
       
   214     else
       
   215         {
       
   216         User::Leave( KErrNotReady );
       
   217         }
       
   218     __VTPRINTEXIT( "RV.StartVideoL" )
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CVtEngRemoteVideo::StopVideoRendering
       
   223 // Stops rendering of remote video.
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CVtEngRemoteVideo::StopVideoRendering()
       
   227     {
       
   228     __VTPRINTENTER( "RV.StopVideoRendering" )
       
   229     // Stop only if active
       
   230     if( iDrawer->GetDsaState() )
       
   231         {
       
   232         __VTPRINT( DEBUG_MEDIA, "RV.Stopping" )
       
   233         iDrawer->BaseStopDraw();
       
   234         }
       
   235     __VTPRINTEXIT( "RV.StopVideoRendering" )
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CVtEngRemoteVideo::AddVideoSinkL
       
   240 // Adds a sink for video to proto.
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 TInt CVtEngRemoteVideo::AddVideoSinkL( TInt aChannelId )
       
   244     {
       
   245     __VTPRINTENTER( "RV.AddVideoSinkL" )
       
   246     if ( iDisplaySink == NULL )
       
   247         {
       
   248         User::Leave( KErrNotReady );
       
   249         }
       
   250     TInt id = iSessionCommand.AddVideoSinkL(
       
   251         aChannelId, *iDisplaySink );
       
   252     iDrawer->VideoSinkAdded();
       
   253     __VTPRINTEXITR( "RV.AddVideoSinkL id=%d", id )
       
   254     return id;
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CVtEngRemoteVideo::AddAudioSinkL
       
   259 // Adds a sink for audio to proto.
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 TInt CVtEngRemoteVideo::AddAudioSinkL( TInt aChannelId )
       
   263     {
       
   264     __VTPRINTENTER( "RV.AddAudioSinkL" )
       
   265     if ( iAudioSink == NULL )
       
   266         {
       
   267         User::Leave( KErrNotReady );
       
   268         }
       
   269     TInt id = iSessionCommand.AddAudioSinkL( aChannelId, *iAudioSink );
       
   270     __VTPRINTEXITR( "RV.AddAudioSinkL id=%d", id )
       
   271     return id;
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CVtEngRemoteVideo::GetDsaState
       
   276 // Returns state of Direct Screen Access.
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 TBool CVtEngRemoteVideo::GetDsaState() const
       
   280     {
       
   281     return iDrawer->GetDsaState();
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CVtEngRemoteVideo::PauseVideoL
       
   286 //
       
   287 // For an incoming track  this function pauses sending
       
   288 // media to the sink (output device) and stops the sink.
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 TInt CVtEngRemoteVideo::PauseVideoL()
       
   292     {
       
   293     __VTPRINTENTER( "RV.PauseVideoL" )
       
   294     if ( iDisplaySink == NULL )
       
   295         {
       
   296         User::Leave( KErrNotReady );
       
   297         }
       
   298     TInt cmdId = iSessionCommand.PauseVideoL( *iDisplaySink );
       
   299     __VTPRINTEXITR( "RV.PauseVideoL id=%d", cmdId )
       
   300     return cmdId;
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CVtEngRemoteVideo::AudioSink
       
   305 // Returns audio sink.
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 MVTAudioSink* CVtEngRemoteVideo::AudioSink()
       
   309     {
       
   310     return iAudioSink;
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CVtEngRemoteVideo::SetUIForegroundL
       
   315 // Sets UI foreground state.
       
   316 // -----------------------------------------------------------------------------
       
   317 void CVtEngRemoteVideo::SetUIForegroundL( TBool aForeground )
       
   318     {
       
   319     __VTPRINTENTER( "RV.SetUIForegroundL" )
       
   320     if( !iDisplaySink )
       
   321         {
       
   322         User::Leave( KErrNotReady );
       
   323         }
       
   324     if( aForeground )
       
   325         {
       
   326         __VTPRINT( DEBUG_MEDIA, " RV.Resuming" )
       
   327         iDisplaySink->Resume();
       
   328         }
       
   329     else
       
   330         {
       
   331         __VTPRINT( DEBUG_MEDIA, " RV.Pausing" )
       
   332         iDisplaySink->Pause();
       
   333         }
       
   334     iDrawer->BaseSetUIForegroundL( aForeground );
       
   335     __VTPRINTEXIT( "RV.SetUIForegroundL" )
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CVtEngRemoteVideo::RequestLastFrame
       
   340 // Request update last remote video frame through MVtEngFrameObserver::vtSetFrame
       
   341 // -----------------------------------------------------------------------------
       
   342 void CVtEngRemoteVideo::RequestLastFrame()
       
   343     {
       
   344     __VTPRINTENTER( "RV.RequestLastFrame" )
       
   345     if(iDrawer)
       
   346         iDrawer->BaseRequestLastFrame();
       
   347 __VTPRINTEXIT( "RV.RequestLastFrame" )
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CVtEngRemoteVideo::CVtEngDraw::~CVtEngDraw
       
   352 // Destructor. Cannot leave.
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 CVtEngRemoteVideo::CVtEngDraw::~CVtEngDraw()
       
   356     {
       
   357     __VTPRINTENTER( "RVD.~" )
       
   358     Cancel();
       
   359     delete iWatcher;
       
   360     delete iDSA;
       
   361     if ( iDisplaySink )
       
   362         {
       
   363         iDisplaySink->Destroy();
       
   364         }
       
   365     __VTPRINTEXIT( "RVD.~" )
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CVtEngRemoteVideo::CVtEngDraw::CVtEngDraw
       
   370 // C++ constructor. Cannot leave.
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 CVtEngRemoteVideo::CVtEngDraw::CVtEngDraw( MDisplaySinkObserver* aObserver ) :
       
   374     CActive( KVtEngRemoteDrawPriority ), iCheckpoint( KVtEngWatcherThreshold ),
       
   375     iObserver( aObserver ), iCallback( WatcherExpired, this ),
       
   376     iDSUpdated( ETrue )
       
   377     {
       
   378     iSourceSize = TSize( KVtEngRemoteVideoDefaultWidth,
       
   379             KVtEngRemoteVideoDefaultHeight );
       
   380     CActiveScheduler::Add( this );
       
   381     }
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CVtEngRemoteVideo::CVtEngDraw::ConstructL
       
   385 // Symbian 2nd phase constructor can leave.
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 void CVtEngRemoteVideo::CVtEngDraw::ConstructL( )
       
   389     {
       
   390     __VTPRINTENTER( "RVD.ConstructL" )
       
   391     BaseConstructL();
       
   392     // Create sink
       
   393     iDisplaySink = CreateSinkL();
       
   394     iWatcher = CPeriodic::NewL( KVtEngStoppedRenderPriority );
       
   395     __VTPRINTEXIT( "RVD.ConstructL" )
       
   396     }
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // CVtEngRemoteVideo::CVtEngDraw::AbortNow
       
   400 // Aborts DSA when requested by Window Server.
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void CVtEngRemoteVideo::CVtEngDraw::AbortNow(
       
   404     RDirectScreenAccess::TTerminationReasons /*aReason*/ )
       
   405     {
       
   406     __VTPRINTENTER( "RVD.AbortNow" )
       
   407     ClearFlag( EReadyForeground | EStarted );
       
   408     BaseAbortNow();
       
   409     __VTPRINTEXIT( "RVD.AbortNow" )
       
   410     }
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // CVtEngRemoteVideo::CVtEngDraw::Restart
       
   414 // Restarts DSA.
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 void CVtEngRemoteVideo::CVtEngDraw::Restart(
       
   418     RDirectScreenAccess::TTerminationReasons /*aReason*/ )
       
   419     {
       
   420     __VTPRINTENTER( "RVD.Restart" )
       
   421     TRAPD( err,
       
   422         {
       
   423         if ( !IsFlag( EStarted ) )
       
   424             {
       
   425             if ( !iDSA->IsActive() )
       
   426                 {
       
   427                 iDSA->StartL();
       
   428                 }
       
   429             SetFlag( EStarted );
       
   430             }
       
   431         if ( !Config().iClipRect.IsEmpty() )
       
   432             {
       
   433             __VTPRINT3( DEBUG_MEDIA, "RVD.Restart iClipRect.iTl (%d, %d)",
       
   434                 Config().iClipRect.iTl.iX, Config().iClipRect.iTl.iY );
       
   435             __VTPRINT3( DEBUG_MEDIA, "RVD.Restart iClipRect.iBr (%d, %d)",
       
   436                 Config().iClipRect.iBr.iX, Config().iClipRect.iBr.iY );
       
   437             iDSA->Gc()->SetClippingRect( Config().iClipRect );
       
   438             }
       
   439         BaseRestartL();
       
   440         } );
       
   441     if ( err != KErrNone )
       
   442         {
       
   443         ClearFlag( EReadyForeground );
       
   444         }
       
   445     else
       
   446         {
       
   447         SetFlag( EReadyForeground );
       
   448         }
       
   449 
       
   450     __VTPRINT2( DEBUG_MEDIA, "RVD.Restart flags %d", iFlags )
       
   451     if ( iCheckpoint == KVtEngWatcherThreshold )
       
   452         {
       
   453         __VTPRINT( DEBUG_MEDIA | DEBUG_RETURN, "RVD.Restart RFs" )
       
   454         TRAP( err, BaseRefreshL() );
       
   455         }
       
   456     __VTPRINTEXITR( "RVD.Restart %d", err )
       
   457     }
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // CVtEngRemoteVideo::CVtEngDraw::GetDsaState
       
   461 // Returns the state of DSA: is drawing ongoing.
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 TBool CVtEngRemoteVideo::CVtEngDraw::GetDsaState() const
       
   465     {
       
   466     __VTPRINTENTER( "RVD.GetDsaState" )
       
   467     TBool active( EFalse );
       
   468     active = IsFlag( ERemoteVideoDrawing );
       
   469     __VTPRINTEXITR( "RVD.GetDsaState is active=%d", active )
       
   470     return active;
       
   471     }
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 // CVtEngRemoteVideo::CVtEngDraw::WatcherExpired
       
   475 // Checks if frame watcher has expired, ie. no frames are received.
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 TInt CVtEngRemoteVideo::CVtEngDraw::WatcherExpired( TAny* aAny )
       
   479     {
       
   480     CVtEngRemoteVideo::CVtEngDraw* drawer =
       
   481         reinterpret_cast<CVtEngRemoteVideo::CVtEngDraw*>( aAny );
       
   482     drawer->HandleWatcherExpired();
       
   483     return KErrNone;
       
   484     }
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // CVtEngRemoteVideo::CVtEngDraw::HandleWatcherExpired
       
   488 // Does the checking for frame reception.
       
   489 // If not receiving, notify using client (VT UI).
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 void CVtEngRemoteVideo::CVtEngDraw::HandleWatcherExpired()
       
   493     {
       
   494     __VTPRINTENTER( "RVD.WatcherExpired" )
       
   495     if ( IsFlag( EStarted ) )
       
   496         {
       
   497         __VTPRINT2( DEBUG_MEDIA | DEBUG_RETURN, "RVD.WatcherExpired RF:%d",
       
   498             iCheckpoint )
       
   499         if ( iCheckpoint != KVtEngWatcherThreshold &&
       
   500              IsFlag( EFirstFrameReceived ) )
       
   501             {
       
   502             __VTPRINT( DEBUG_MEDIA | DEBUG_RETURN, "RVD.WatcherExpired RF" )
       
   503             TRAP_IGNORE( BaseRefreshL() );
       
   504             }
       
   505         iCheckpoint--;
       
   506         // Not under zero though.
       
   507         if ( iCheckpoint < 0 )
       
   508             {
       
   509             iCheckpoint = 0;
       
   510             }
       
   511         }
       
   512     __VTPRINTEXIT( "RVD.WatcherExpired" )
       
   513     }
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // CVtEngRemoteVideo::CVtEngDraw::SetFlag
       
   517 // Sets flags.
       
   518 // -----------------------------------------------------------------------------
       
   519 //
       
   520 void CVtEngRemoteVideo::CVtEngDraw::SetFlag( TUint aFlags )
       
   521     {
       
   522     iFlags |= aFlags;
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // CVtEngRemoteVideo::CVtEngDraw::ClearFlag
       
   527 // Clears (unsets) flags.
       
   528 // -----------------------------------------------------------------------------
       
   529 //
       
   530 void CVtEngRemoteVideo::CVtEngDraw::ClearFlag( TUint aFlags )
       
   531     {
       
   532     iFlags &= ~aFlags;
       
   533     }
       
   534 
       
   535 // -----------------------------------------------------------------------------
       
   536 // CVtEngRemoteVideo::CVtEngDraw::IsFlag
       
   537 // Tests a flag.
       
   538 // -----------------------------------------------------------------------------
       
   539 //
       
   540 TBool CVtEngRemoteVideo::CVtEngDraw::IsFlag( TUint aFlag ) const
       
   541     {
       
   542     return ( iFlags & aFlag ) != 0 ;
       
   543     }
       
   544 
       
   545 // -----------------------------------------------------------------------------
       
   546 // CVtEngRemoteVideo::CVtEngDraw::VideoSinkAdded
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 void CVtEngRemoteVideo::CVtEngDraw::VideoSinkAdded()
       
   550     {
       
   551     // By clearing this flag every time when sink is added, we assure that
       
   552     // blind icon is correctly faded in UI.
       
   553     ClearFlag( EFirstFrameReceived );
       
   554     }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CVtEngRemoteVideo::CVtEngDraw::Activate
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 void CVtEngRemoteVideo::CVtEngDraw::Activate()
       
   561     {
       
   562     __VTPRINTENTER( "RVD.Activate" )
       
   563     if ( !IsActive() )
       
   564         {
       
   565         __VTPRINT( DEBUG_MEDIA, "RVD.Activate setting active" )
       
   566         iStatus = KRequestPending;
       
   567         SetActive();
       
   568         }
       
   569     __VTPRINTEXIT( "RVD.Activate" )
       
   570     }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CVtEngRemoteVideo::CVtEngDraw::ConfigUpdatedL
       
   574 // Set drawing configuration.
       
   575 // -----------------------------------------------------------------------------
       
   576 //
       
   577 void CVtEngRemoteVideo::CVtEngDraw::ConfigUpdatedL()
       
   578     {
       
   579     __VTPRINTENTER( "RVD.ConfigUpdatedL" )
       
   580     ClearFlag( EFlagInitialized );
       
   581     TRAPD( err, {
       
   582             BaseVerifyConfigL();
       
   583             
       
   584             if ( IsFlag( EReadyInternal ) )
       
   585                 {
       
   586                 __VTPRINT( DEBUG_MEDIA, "RVD.SetC started" )
       
   587                 SetFlag( EStarted );
       
   588                 __VTPRINT( DEBUG_MEDIA, "RVD.SetC notify rvd start" )
       
   589                 }
       
   590             BaseRefreshBitmapsL();
       
   591             } );
       
   592     if ( err != KErrNone )
       
   593         {
       
   594         __VTPRINT2( DEBUG_MEDIA | DEBUG_RETURN, "RVD.SetC FAILED %d", err )
       
   595         CVtEngEventManager::NotifyEvent( KVtEngMediaInitFailure );
       
   596         }
       
   597     User::LeaveIfError( err );
       
   598     SetFlag( EFlagInitialized );
       
   599     __VTPRINTEXIT( "RVD.ConfigUpdatedL" )
       
   600     }
       
   601 
       
   602 // -----------------------------------------------------------------------------
       
   603 // CVtEngRemoteVideo::CVtEngDraw::DisplaySink
       
   604 // Returns used display sink.
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 MDisplaySink* CVtEngRemoteVideo::CVtEngDraw::DisplaySink()
       
   608     {
       
   609     return iDisplaySink;
       
   610     }
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // CVtEngRemoteVideo::CVtEngDraw::DoCancel
       
   614 // -----------------------------------------------------------------------------
       
   615 //
       
   616 void CVtEngRemoteVideo::CVtEngDraw::DoCancel()
       
   617     {
       
   618     __VTPRINTENTER( "RVD.DoCancel" )
       
   619     BaseDoCancel();
       
   620     iDisplaySink->Release();
       
   621     ClearFlag( EStarted | EFrameWatcherExpired );
       
   622     __VTPRINTEXIT( "RVD.DoCancel" )
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // CVtEngRemoteVideo::CVtEngDraw::RunError
       
   627 // -----------------------------------------------------------------------------
       
   628 //
       
   629 #ifdef VTDEBUG
       
   630 TInt CVtEngRemoteVideo::CVtEngDraw::RunError( TInt aError )
       
   631 #else
       
   632 TInt CVtEngRemoteVideo::CVtEngDraw::RunError( TInt /* aError */ )
       
   633 #endif // VTDEBUG
       
   634     {
       
   635     __VTPRINTENTER( "RVD.RunError" )
       
   636     ClearFlag( EStarted );
       
   637     BaseStopDraw();
       
   638     CVtEngEventManager::NotifyEvent( KVtEngRemoteVideoStopped );
       
   639     __VTPRINTEXITR( "RVD.RunError %d", aError )
       
   640     return KErrNone;
       
   641     }
       
   642 
       
   643 // -----------------------------------------------------------------------------
       
   644 // CVtEngRemoteVideo::CVtEngDraw::CreateAndStartDSAL
       
   645 // Create DSA instance.
       
   646 // -----------------------------------------------------------------------------
       
   647 //
       
   648 void CVtEngRemoteVideo::CVtEngDraw::CreateAndStartDSAL()
       
   649     {
       
   650     __VTPRINTENTER( "RVD.CreateAndStartDSAL" )
       
   651     delete iDSA;
       
   652     iDSA = NULL;
       
   653     iDSA = CDirectScreenAccess::NewL(
       
   654     *Config().iWsSession,
       
   655     *Config().iWsSreenDevice,
       
   656     *Config().iWindow,
       
   657     *this );
       
   658     iDSA->StartL();
       
   659     if ( !Config().iClipRect.IsEmpty() )
       
   660         {
       
   661         __VTPRINT( DEBUG_MEDIA, "RVD.CreateAndStartDSAL setting cliprect" )
       
   662         iDSA->Gc()->SetClippingRect( Config().iClipRect );
       
   663         }
       
   664     __VTPRINTEXIT( "RVD.CreateAndStartDSAL" )
       
   665     }
       
   666 
       
   667 // -----------------------------------------------------------------------------
       
   668 // CVtEngRemoteVideo::VideoFrameSizeChanged
       
   669 // Callback from DisplaySink to inform the size change
       
   670 // -----------------------------------------------------------------------------
       
   671 //
       
   672 void CVtEngRemoteVideo::
       
   673     VideoFrameSizeChangedL( const TSize& /* aFrom */, const TSize& aTo )
       
   674     {
       
   675     __VTPRINTENTER( "RVD.VideoFrameSizeChangedL" )
       
   676     __VTPRINT( DEBUG_MEDIA , " ======= RV.RVD.VideoFrameSizeChangedL ========" )
       
   677     __VTPRINT2( DEBUG_MEDIA , "    aTo.iWidth: %d", aTo.iWidth)
       
   678     __VTPRINT2( DEBUG_MEDIA , "    aTo.iHeight: %d", aTo.iHeight )
       
   679     __VTPRINT( DEBUG_MEDIA , " ======= RV.RVD.VideoFrameSizeChangedL ========" )
       
   680 
       
   681     // Notification of changed layout.
       
   682     if ( aTo.iHeight == KVtEngResolutionQCIFHeight &&
       
   683         aTo.iWidth == KVtEngResolutionQCIFWidth )
       
   684         {
       
   685 	    // Store the new size.
       
   686 	    iDrawer->iSourceSize = aTo;
       
   687         CVtEngEventManager::NotifyEvent( KVtEngResolutionToQCIF );
       
   688         }
       
   689     else if ( aTo.iHeight == KVtEngResolutionSQCIFHeight &&
       
   690         aTo.iWidth == KVtEngResolutionSQCIFWidth )
       
   691         {
       
   692 	    // Store the new size.
       
   693 	    iDrawer->iSourceSize = aTo;
       
   694         CVtEngEventManager::NotifyEvent( KVtEngResolutionToSQCIF );
       
   695         }
       
   696     else
       
   697         {
       
   698         // Unlisted resolution.
       
   699         __VTPRINTEXITR( "RVD.VideoFrameSizeChangedL %d", 0 )
       
   700         return;
       
   701         }
       
   702 
       
   703     iDrawer->BaseVideoFrameSizeChangedL( aTo );
       
   704 
       
   705     __VTPRINTEXITR( "RVD.VideoFrameSizeChangedL %d", 1 )
       
   706     }
       
   707 
       
   708 // VtEngDrawFactory
       
   709 
       
   710 // -----------------------------------------------------------------------------
       
   711 // VtEngDrawFactory::CreateDrawerL
       
   712 // -----------------------------------------------------------------------------
       
   713 //
       
   714 MVtEngDraw* VtEngDrawFactory::CreateDrawerL( MDisplaySinkObserver* aObserver, TBool aSupportNGA )
       
   715     {
       
   716     __VTPRINTENTER( "VtEngDrawFactory.CreateDrawerL" )
       
   717     MVtEngDraw* drawer = NULL;
       
   718     if(aSupportNGA)
       
   719         {
       
   720         drawer = CVtEngDrawNGA::NewL( aObserver );
       
   721         }
       
   722     else
       
   723         {
       
   724     if ( FeatureManager::FeatureSupported( KFeatureIdDisplayPost ) )
       
   725 	    {
       
   726 	    drawer = CVtEngDrawDP::NewL( aObserver );
       
   727 	    }
       
   728         else
       
   729 	    {
       
   730 	    drawer = CVtEngDrawDSA::NewL( aObserver );
       
   731 	    }
       
   732         }
       
   733     __VTPRINTEXIT( "VtEngDrawFactory.CreateDrawerL" )
       
   734     return drawer;
       
   735     }
       
   736 
       
   737 //  End of File