messagingappbase/msgeditor/mediacontrolsrc/MsgVideoControl.cpp
changeset 0 72b543305e3a
child 15 52d61119153d
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005 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:  
       
    15 *       MsgEditor video media control - a Message Editor Base control.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "MsgVideoControl.h"
       
    23 
       
    24 #include <AudioPreference.h>
       
    25 #include <AknsDrawUtils.h>
       
    26 #include <DRMCommon.h>
       
    27 #include <mmf/common/mmferrors.h>              // KErrMMPartialPlayback
       
    28 
       
    29 #include <MsgEditorCommon.h>
       
    30 
       
    31 #include "MsgFrameControl.h"
       
    32 #include "MsgIconControl.h"
       
    33 #include "MsgVideoAreaControl.h"
       
    34 
       
    35 #include "MsgMediaControlLogging.h"
       
    36 
       
    37 // ==========================================================
       
    38 
       
    39 // EXTERNAL DATA STRUCTURES
       
    40 
       
    41 // EXTERNAL FUNCTION PROTOTYPES
       
    42 
       
    43 // CONSTANTS
       
    44 
       
    45 // MACROS
       
    46 
       
    47 // LOCAL CONSTANTS AND MACROS
       
    48 
       
    49 //used to reset inactivity timer after one sec so that backlight will not
       
    50 // be turned on during video playback.
       
    51 const TInt KResetInactivityAfterOneSecond = 2000000;   // 2s
       
    52 
       
    53 // MODULE DATA STRUCTURES
       
    54 
       
    55 // LOCAL FUNCTION PROTOTYPES
       
    56 
       
    57 // ================= MEMBER FUNCTIONS =======================
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CMsgVideoControl::CMsgVideoControl
       
    61 //
       
    62 // Constructor. Maximum video area is calculated so that height comes from 
       
    63 // mainpane height and width comes from data pane height. This video will
       
    64 // use whole application area excluding scrollbar area.
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CMsgVideoControl::CMsgVideoControl( MMsgBaseControlObserver& aBaseControlObserver,
       
    68                                     TMdaPriority aPriority,
       
    69                                     TMdaPriorityPreference  aPreference,
       
    70                                     TInt aFlags ) :
       
    71     CMsgMediaControl( aBaseControlObserver, EMsgComponentIdVideo, EMsgVideoControl ),
       
    72     iMaxVideoArea( MsgEditorCommons::MsgMainPane() ),
       
    73     iMaxVolume( 1 ),
       
    74     iFlags( aFlags ),
       
    75     iHasVideo( ETrue ),
       
    76     iPriority( aPriority ),
       
    77     iPreference( aPreference )
       
    78     {
       
    79     if ( iFlags & ENoPlayback )
       
    80         {
       
    81         iControlType = EMsgImageControl;
       
    82         }
       
    83         
       
    84     iMaxVideoArea.SetWidth( MsgEditorCommons::MsgDataPane().Width() );
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // CMsgVideoControl::ConstructL
       
    89 // ---------------------------------------------------------
       
    90 //
       
    91 void CMsgVideoControl::ConstructL( CMsgEditorView& aParent, MMsgAsyncControlObserver* aObserver )
       
    92     {
       
    93     BaseConstructL( aParent, aObserver );
       
    94         
       
    95     SetRect( iMaxVideoArea );
       
    96     
       
    97     iTimer = CPeriodic::NewL( EPriorityLow );
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CMsgVideoControl::NewL
       
   102 //
       
   103 // Two-phased constructor.
       
   104 // ---------------------------------------------------------
       
   105 //
       
   106 EXPORT_C CMsgVideoControl* CMsgVideoControl::NewL( CMsgEditorView& aParent,
       
   107                                                    MMsgAsyncControlObserver* aObserver,
       
   108                                                    TMdaPriority aPriority,
       
   109                                                    TMdaPriorityPreference  aPreference,
       
   110                                                    TInt aFlags )
       
   111     {
       
   112     CMsgVideoControl* self = new( ELeave ) CMsgVideoControl( aParent, aPriority, aPreference, aFlags );
       
   113     
       
   114     CleanupStack::PushL( self );
       
   115     self->ConstructL( aParent, aObserver );
       
   116     CleanupStack::Pop( self );
       
   117     
       
   118     return self;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CMsgVideoControl::~CMsgVideoControl
       
   123 //
       
   124 // Destructor
       
   125 // ---------------------------------------------------------
       
   126 //
       
   127 CMsgVideoControl::~CMsgVideoControl()
       
   128     {
       
   129     delete iVideoPlayer;
       
   130     delete iIdle;
       
   131     
       
   132     iVideoFile.Close();
       
   133     
       
   134     delete iTimer;
       
   135     delete iVideoAreaControl;
       
   136     }
       
   137 
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CMsgVideoControl::HasAudio
       
   141 //
       
   142 // Check if video clip has audio in.
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 EXPORT_C TBool CMsgVideoControl::HasAudioL( void ) const
       
   146     {
       
   147     if ( iVideoPlayer && Error() == KErrNone )
       
   148         {
       
   149         return iVideoPlayer->AudioEnabledL();
       
   150         }
       
   151     return EFalse;
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------
       
   155 // CMsgVideoControl::SetVolume
       
   156 //
       
   157 // Set volume level.
       
   158 // ---------------------------------------------------------
       
   159 //
       
   160 EXPORT_C void CMsgVideoControl::SetVolumeL( TInt aVolume )
       
   161     {
       
   162     MSGMEDIACONTROLLOGGER_WRITEF( _L("MsgVideoControl::SetVolumeL(): HasAudioL(): %d, iMaxVolume: %d, aVolume: %d"),  HasAudioL(), iMaxVolume, aVolume);
       
   163     if ( HasAudioL() )
       
   164         {
       
   165         iVideoPlayer->SetVolumeL( aVolume );
       
   166         iVolume = iVideoPlayer->Volume();
       
   167         }
       
   168     }
       
   169     
       
   170 // ---------------------------------------------------------
       
   171 // CMsgVideoControl::FocusChanged
       
   172 //
       
   173 // Called when focus is changing. Playing is paused or stopped
       
   174 // depending on iContinueOnFocus flag when focus moves out of video control. 
       
   175 // When focus moved back to control playing is started automatically
       
   176 // if iContinueOnFocus flag is set.
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CMsgVideoControl::FocusChanged( TDrawNow aDrawNow )
       
   180     {
       
   181     MSGMEDIACONTROLLOGGER_WRITEF( _L("MsgVideoControl : FocusChanged: IsFocused(): %d" ), IsFocused() );
       
   182     if ( IsFocused() )
       
   183         {
       
   184         if ( iState == EMsgAsyncControlStatePaused &&
       
   185              iContinueOnFocus )
       
   186             {
       
   187             MSGMEDIACONTROLLOGGER_WRITE( "MsgVideoControl : FocusChanged - Delayed start **" );
       
   188             // We must use CIdle to perform Play since
       
   189             // "SizeChanged" event comes only after "FocusChanged"
       
   190             // and thus the coordinates of the video control might
       
   191             // be false at this stage.
       
   192             delete iIdle;
       
   193             iIdle = NULL;
       
   194             TRAP_IGNORE( iIdle = CIdle::NewL( CActive::EPriorityIdle ) );
       
   195             if ( iIdle ) 
       
   196                 {
       
   197                 iIdle->Start( TCallBack( DelayedPlay, this ) );
       
   198                 }
       
   199             else
       
   200                 {
       
   201                 MSGMEDIACONTROLLOGGER_WRITE( "MsgVideoControl : FocusChanged - Error in creating iIdle **" );
       
   202                 Stop();
       
   203                 }
       
   204             
       
   205             }
       
   206         }
       
   207     else
       
   208         {
       
   209         if ( iContinueOnFocus && 
       
   210              iState == EMsgAsyncControlStatePlaying )
       
   211             {
       
   212             MSGMEDIACONTROLLOGGER_WRITE( "MsgVideoControl : FocusChanged - Pausing video ..." );
       
   213             TRAPD( err, PauseL() );
       
   214             if ( err )
       
   215                 {
       
   216                 MSGMEDIACONTROLLOGGER_WRITE( "MsgVideoControl : FocusChanged - Error in pausing -> Stop it **" );
       
   217                 Stop();
       
   218                 }
       
   219             }
       
   220         else
       
   221             {
       
   222             MSGMEDIACONTROLLOGGER_WRITE( "MsgVideoControl : FocusChanged - Stopping video **" );
       
   223             Stop();
       
   224             }
       
   225         }
       
   226         
       
   227     CMsgMediaControl::FocusChanged( aDrawNow );
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------
       
   231 // CMsgVideoControl::SetAndGetSizeL
       
   232 //
       
   233 // Calculates and sets the size of the control and returns new size as
       
   234 // reference aSize. Video control uses the whole application area excluding
       
   235 // area that has been reserved for scrollbar when it is used for playback.
       
   236 // Otherwise it uses the same width but height is calculated so that
       
   237 // it will icon height + one line height and rounded up to the next whole line.
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 void CMsgVideoControl::SetAndGetSizeL( TSize& aSize )
       
   241     {
       
   242     MSGMEDIACONTROLLOGGER_WRITEF( _L("MsgVideoControl:: SetAndGetSizeL(): Size: %dx%d"),  aSize.iWidth, aSize.iHeight);
       
   243     
       
   244     aSize.iWidth = iMaxVideoArea.Width();
       
   245     
       
   246     if ( iFlags & ENoPlayback )
       
   247         {
       
   248         aSize.iHeight = iFrame->FrameSize().iHeight;
       
   249         
       
   250         if ( aSize.iHeight % iLineHeight != 0 )
       
   251             {
       
   252             aSize.iHeight += iLineHeight - ( aSize.iHeight % iLineHeight );
       
   253             }
       
   254             
       
   255         aSize.iHeight += iLineHeight;
       
   256         }
       
   257     else
       
   258         {
       
   259         aSize.iHeight = iMaxVideoArea.Height();
       
   260         }
       
   261     
       
   262     MSGMEDIACONTROLLOGGER_WRITEF( _L("MsgVideoControl:: SetAndGetSizeL(): New size: %dx%d"),  aSize.iWidth, aSize.iHeight);
       
   263     SetSize( aSize );
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------
       
   267 // CMsgVideoControl::Reset
       
   268 //
       
   269 // Empties the control and sets icon visible.
       
   270 // ---------------------------------------------------------
       
   271 //
       
   272 void CMsgVideoControl::Reset()
       
   273     {
       
   274     if( iVideoPlayer )
       
   275         {
       
   276         iVideoPlayer->Stop();
       
   277         iVideoPlayer->Close();
       
   278         
       
   279         iTimer->Cancel();
       
   280         
       
   281         delete iVideoPlayer;
       
   282         iVideoPlayer = NULL;
       
   283         }
       
   284         
       
   285     iVideoFile.Close();
       
   286     
       
   287     iVolume = 0;
       
   288     iMaxVolume = 1;
       
   289 
       
   290     SetIconVisible( ETrue );
       
   291     
       
   292     if ( iVideoAreaControl )
       
   293     	{
       
   294         iVideoAreaControl->MakeVisible( EFalse );
       
   295     	}
       
   296     
       
   297     iControlModeFlags |= EMsgControlModeModified;
       
   298     SetState( EMsgAsyncControlStateIdle );
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------
       
   302 // CMsgVideoControl::Draw
       
   303 // Draw the skin background when appriate. Normal icon drawing
       
   304 // is performed when icon is visible. Otherwise when video frame
       
   305 // is visible we just draw the control area around the video frame.
       
   306 // Video controller is responsible of drawing the video frame area.
       
   307 // ---------------------------------------------------------
       
   308 //
       
   309 void CMsgVideoControl::Draw( const TRect& aRect ) const
       
   310     {
       
   311     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : Draw()" );
       
   312     if ( VisiblePlaceholder() )
       
   313         {    
       
   314         // Basic icon drawing from base class when icon is visible.
       
   315         CMsgMediaControl::Draw( aRect );    
       
   316         }
       
   317     else 
       
   318         {
       
   319         if ( !AknsDrawUtils::BackgroundBetweenRects( AknsUtils::SkinInstance(), 
       
   320                                                       AknsDrawUtils::ControlContext( this ), 
       
   321                                                       this, 
       
   322                                                       SystemGc(), 
       
   323                                                       aRect,
       
   324                                                       iVideoFrameArea ) )
       
   325             {
       
   326             SystemGc().SetBrushColor( AKN_LAF_COLOR( 0 ) );
       
   327             SystemGc().SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   328             SystemGc().SetPenStyle( CGraphicsContext::ENullPen );
       
   329             SystemGc().DrawRect( aRect );
       
   330             }
       
   331             
       
   332         if ( !Window().IsFaded() )
       
   333             {
       
   334             // Should prevent race conditions between DSP ans window server.
       
   335             iCoeEnv->WsSession().Flush();
       
   336             TRAP_IGNORE( iVideoPlayer->RefreshFrameL() ) ;
       
   337             }
       
   338         }        
       
   339     }
       
   340 
       
   341 // ---------------------------------------------------------
       
   342 // CMsgVideoControl::HandleResourceChange
       
   343 // ---------------------------------------------------------
       
   344 //
       
   345 void CMsgVideoControl::HandleResourceChange( TInt aType )
       
   346     {
       
   347     CMsgMediaControl::HandleResourceChange( aType ); 
       
   348     
       
   349     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   350         {
       
   351         Stop();
       
   352         TRAP_IGNORE( UpdateScaleFactorL() );
       
   353         
       
   354         iMaxVideoArea = MsgEditorCommons::MsgMainPane();
       
   355         iMaxVideoArea.SetWidth( MsgEditorCommons::MsgDataPane().Width() );
       
   356         }
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------
       
   360 // CMsgVideoControl::SizeChanged
       
   361 //
       
   362 // Called when size is changed.
       
   363 // ---------------------------------------------------------
       
   364 //
       
   365 void CMsgVideoControl::SizeChanged()
       
   366     {
       
   367     MSGMEDIACONTROLLOGGER_WRITEF( _L("MsgVideoControl:: SizeChanged(): New size: %dx%d"),  Size().iWidth, Size().iHeight);
       
   368     
       
   369     CMsgMediaControl::SizeChanged();
       
   370     
       
   371     SetPosition( Rect().iTl );
       
   372     MSGMEDIACONTROLLOGGER_WRITEF( _L("MsgVideoControl:: SizeChanged(): Rect().iTl %dx%d"),  Rect().iTl.iX, Rect().iTl.iY);
       
   373     if ( iVideoPlayer && Error() == KErrNone )
       
   374         { 
       
   375         TRAP_IGNORE( SetVideoFrameSizeL() );
       
   376         }
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------
       
   380 // CMsgVideoControl::LoadL
       
   381 // ---------------------------------------------------------
       
   382 //
       
   383 void CMsgVideoControl::LoadL( RFile& aFileHandle )
       
   384     {
       
   385     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : LoadL()" );
       
   386 
       
   387     iVideoFile.Close();
       
   388     User::LeaveIfError( iVideoFile.Duplicate( aFileHandle ) );
       
   389     
       
   390     if ( !iVideoAreaControl )
       
   391     	{
       
   392         iVideoAreaControl = CMsgVideoAreaControl::NewL( this );
       
   393     	}
       
   394     
       
   395     if ( !iVideoPlayer )
       
   396         {
       
   397         // Disable frame display as video is not yet visible
       
   398         TRect rect;
       
   399         TRect clipRect;
       
   400 
       
   401         // Create VideoPlayerUtility instance
       
   402         iVideoPlayer = CVideoPlayerUtility::NewL(
       
   403                         *this,
       
   404                         iPriority,
       
   405                         iPreference,
       
   406                         ControlEnv()->WsSession(),
       
   407                         *ControlEnv()->ScreenDevice(),    
       
   408                         *iVideoAreaControl->DrawableWindow(),
       
   409                         rect, 
       
   410                         clipRect );
       
   411         // Register for Loading/rebuffering notices
       
   412         iVideoPlayer->RegisterForVideoLoadingNotification( *this );
       
   413         }
       
   414     else
       
   415         {
       
   416         iVideoPlayer->Close();
       
   417         }
       
   418 
       
   419     TMMFileHandleSource mmSource( iVideoFile, iUniqueContentId );
       
   420     iVideoPlayer->OpenFileL( mmSource );        
       
   421 
       
   422     SetState( EMsgAsyncControlStateOpening );
       
   423     
       
   424     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : LoadL()" );
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------
       
   428 // CMsgVideoControl::Cancel
       
   429 // ---------------------------------------------------------
       
   430 //
       
   431 void CMsgVideoControl::Cancel()
       
   432     {
       
   433     if ( iState == EMsgAsyncControlStateOpening )
       
   434         {
       
   435         iVideoPlayer->Close();
       
   436         
       
   437         SetState( EMsgAsyncControlStateIdle );
       
   438         }
       
   439     }
       
   440 
       
   441 // ---------------------------------------------------------
       
   442 // CMsgVideoControl::VideoResolution
       
   443 //
       
   444 // Gives the resolution of the video in display (Symbian OS bitmap)
       
   445 // ---------------------------------------------------------
       
   446 //
       
   447 EXPORT_C TSize CMsgVideoControl::VideoResolutionL() const
       
   448     {
       
   449     TSize retVal( 0, 0 );
       
   450     if ( iVideoPlayer && Error() == KErrNone )
       
   451         {
       
   452         iVideoPlayer->VideoFrameSizeL( retVal );
       
   453         }
       
   454     return retVal;
       
   455     }
       
   456 
       
   457 // ---------------------------------------------------------
       
   458 // DelayedExit
       
   459 // ---------------------------------------------------------
       
   460 //
       
   461 TInt CMsgVideoControl::DelayedPlay( TAny* aThis )
       
   462     {
       
   463     TRAPD( error, static_cast<CMsgVideoControl*>( aThis )->PlayL() );
       
   464     return error;
       
   465     }
       
   466 
       
   467 // ---------------------------------------------------------
       
   468 // CMsgVideoControl::PlayL
       
   469 //
       
   470 // Starts video playback.
       
   471 // ---------------------------------------------------------
       
   472 //
       
   473 void CMsgVideoControl::PlayL()
       
   474     {
       
   475     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : PlayL()" );
       
   476 
       
   477     // When DSP is used for audio/video playing, dsp resources are not always available.
       
   478     // It is handled by setting normal 'ready' icon. No error notes occur.
       
   479     if ( iVideoPlayer && 
       
   480          (  Error() == KErrNone ||
       
   481             (   iState == EMsgAsyncControlStateCorrupt
       
   482             &&  (   Error() == KErrAccessDenied
       
   483                 ||  Error() == KErrSessionClosed ) ) ) && 
       
   484          !( iFlags & ENoPlayback ) )
       
   485         {
       
   486         if ( iHasVideo )
       
   487             {
       
   488             // Only hide icon if video file has video stream.
       
   489             if ( iIconControl->IsVisible() )
       
   490                 {
       
   491                 UpdateScaleFactorL();
       
   492                 
       
   493                 SetIconVisible( EFalse );
       
   494                 iVideoAreaControl->MakeVisible( ETrue );
       
   495                 
       
   496                 // Enable frame display        	
       
   497                 SetVideoFrameSizeL();
       
   498                 }
       
   499             
       
   500             iTimer->Cancel(); //just in case
       
   501             
       
   502             // Disable backlight turn off during video playback when video contains
       
   503             // video stream.
       
   504             iTimer->Start( KResetInactivityAfterOneSecond,
       
   505                            KResetInactivityAfterOneSecond,
       
   506                            TCallBack( DoResetInactivityTimer, NULL ) );
       
   507             }
       
   508         	
       
   509         iVideoPlayer->Play();
       
   510         
       
   511         if ( iState == EMsgAsyncControlStatePaused )
       
   512             {
       
   513             SetState( EMsgAsyncControlStatePlaying );
       
   514             }
       
   515         else
       
   516             {
       
   517             if (iState == EMsgAsyncControlStateReady )
       
   518                 {
       
   519                 // First time
       
   520                 SetState( EMsgAsyncControlStateAboutToPlay );
       
   521                 }
       
   522             else
       
   523                 {
       
   524                 // State must be stop. Video has earlier played
       
   525                 SetState( EMsgAsyncControlStatePlaying );
       
   526                 }
       
   527             }
       
   528         }
       
   529     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : PlayL()" );
       
   530     }
       
   531 
       
   532 // ---------------------------------------------------------
       
   533 // CMsgVideoControl::Stop
       
   534 //
       
   535 // Stops video.
       
   536 // ---------------------------------------------------------
       
   537 //
       
   538 void CMsgVideoControl::Stop()
       
   539     {
       
   540     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : Stop()" );
       
   541 
       
   542     if ( iState == EMsgAsyncControlStatePlaying ||
       
   543          iState == EMsgAsyncControlStatePaused )
       
   544         {
       
   545         iVideoPlayer->Stop();
       
   546         
       
   547         // Enable backlight to turn on after video playback has been stopped.
       
   548         iTimer->Cancel();
       
   549         
       
   550         SetState( EMsgAsyncControlStateStopped );
       
   551         }
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------
       
   555 // CMsgVideoControl::PauseL
       
   556 //
       
   557 // Pauses video.
       
   558 // ---------------------------------------------------------
       
   559 //
       
   560 void CMsgVideoControl::PauseL()
       
   561     {
       
   562     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : PauseL()" );
       
   563     if ( iState == EMsgAsyncControlStatePlaying )
       
   564         {
       
   565         iVideoPlayer->PauseL();
       
   566         
       
   567         // Enable backlight to turn on after video playback has been paused.
       
   568         iTimer->Cancel();
       
   569         
       
   570         SetState( EMsgAsyncControlStatePaused );
       
   571         }
       
   572     }
       
   573 
       
   574 // ---------------------------------------------------------
       
   575 // CMsgVideoControl::IsOffScreen
       
   576 //
       
   577 // Returns ETrue if control is off screen.
       
   578 // ---------------------------------------------------------
       
   579 //
       
   580 EXPORT_C TBool CMsgVideoControl::IsOffScreen() const
       
   581     {
       
   582     TRect rect( Rect() );
       
   583     if ( rect.iTl.iY < 0 || rect.iBr.iY > iMaxVideoArea.Height() )
       
   584         {
       
   585         return ETrue;
       
   586         }
       
   587     else
       
   588         {
       
   589         return EFalse;
       
   590         }
       
   591     }
       
   592 
       
   593 
       
   594 // ---------------------------------------------------------
       
   595 // CMsgVideoControl::SetVideoFrameSizeL
       
   596 //
       
   597 // ---------------------------------------------------------
       
   598 //
       
   599 void CMsgVideoControl::SetVideoFrameSizeL()
       
   600     {
       
   601     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : DoSizeChangedL()" );
       
   602     
       
   603     TRect rect;
       
   604     TRect clipRect;
       
   605     
       
   606 	if ( VisiblePlaceholder() )
       
   607 		{
       
   608 		// Disable frame display if icon is visible
       
   609 		iVideoFrameArea = TRect();
       
   610 		}
       
   611 	else
       
   612 	    {
       
   613 	    TSize videoSize( iOriginalSize.iWidth * iScaleFactor,
       
   614                          iOriginalSize.iHeight * iScaleFactor );
       
   615         
       
   616         TPoint videoPosition( Rect().Center() );
       
   617         
       
   618         videoPosition.iX -= videoSize.iWidth / 2;
       
   619         videoPosition.iY -= videoSize.iHeight / 2;
       
   620         
       
   621         // Rect & clipRect are relative to screen coordinates.
       
   622         rect =  TRect( videoPosition, videoSize );
       
   623         rect.Move( 0, iMaxVideoArea.iTl.iY );
       
   624 
       
   625         clipRect = rect;
       
   626         clipRect.iTl.iY = Max( clipRect.iTl.iY, iMaxVideoArea.iTl.iY );
       
   627         clipRect.iTl.iY = Min( clipRect.iTl.iY, iMaxVideoArea.iBr.iY );
       
   628         clipRect.iBr.iY = Min( clipRect.iBr.iY, iMaxVideoArea.iBr.iY );
       
   629         clipRect.iBr.iY = Max( clipRect.iBr.iY, iMaxVideoArea.iTl.iY );
       
   630 
       
   631         // iVideoFrameArea is relative to window coordinates.
       
   632         iVideoFrameArea = clipRect;
       
   633         iVideoFrameArea.Move( 0, -iBaseControlObserver->ViewRect().iTl.iY );
       
   634 
       
   635         MSGMEDIACONTROLLOGGER_WRITE( "MsgVideoControl : DoSizeChangedL() - Calling  SetDisplayWindowL" );
       
   636         MSGMEDIACONTROLLOGGER_WRITEF( _L("MsgVideoControl:: SizeChanged(): rect (%d,%d),( %d,%d)"),  rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
       
   637         MSGMEDIACONTROLLOGGER_WRITEF( _L("MsgVideoControl:: SizeChanged(): cliRect (%d,%d),( %d,%d)"),  clipRect.iTl.iX, clipRect.iTl.iY, clipRect.iBr.iX, clipRect.iBr.iY);
       
   638 	    }
       
   639 	
       
   640 	// iVideoAreaControl is relative to screen coordinates.
       
   641     iVideoPlayer->SetDisplayWindowL(
       
   642         ControlEnv()->WsSession(),
       
   643         *ControlEnv()->ScreenDevice(),
       
   644         *iVideoAreaControl->DrawableWindow(),
       
   645         rect,
       
   646         clipRect );
       
   647     iVideoAreaControl->SetRect( iVideoFrameArea );
       
   648     
       
   649     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : DoSizeChangedL()" );
       
   650     }
       
   651 
       
   652 
       
   653 // =========================================================
       
   654 // Callbacks from VideoPlayerutility
       
   655 // =========================================================
       
   656 
       
   657 // ---------------------------------------------------------
       
   658 // see MVideoPlayerUtilityObserver::MvpuoOpenComplete
       
   659 // ---------------------------------------------------------
       
   660 //
       
   661 void CMsgVideoControl::MvpuoOpenComplete( TInt aError )
       
   662     {
       
   663     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : MvpuoOpenComplete()" );
       
   664     
       
   665     // Close the handle now
       
   666     iVideoFile.Close();
       
   667     
       
   668     iMaxVolume = iVideoPlayer->MaxVolume();
       
   669     iVolume = iVideoPlayer->Volume();
       
   670 
       
   671     // Needed so that video controller won't consume DRM rights automatically.    
       
   672     MMMFDRMCustomCommand* customCommand = iVideoPlayer->GetDRMCustomCommand();
       
   673     if ( customCommand )
       
   674         {
       
   675         customCommand->DisableAutomaticIntent( ETrue );            
       
   676         }
       
   677     
       
   678     HandleCallback( aError, iState );
       
   679     // Remember that MvpuoPrepareComplete() follows
       
   680     
       
   681     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : MvpuoOpenComplete()" );
       
   682     }
       
   683 
       
   684 // ---------------------------------------------------------
       
   685 // see MVideoPlayerUtilityObserver::MvpuoPrepareComplete
       
   686 // ---------------------------------------------------------
       
   687 //
       
   688 void CMsgVideoControl::MvpuoPrepareComplete( TInt aError )
       
   689     {
       
   690     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : MvpuoPrepareComplete()" );
       
   691     
       
   692     // Determine whether video file contains video stream (i.e. it has something
       
   693     // to show on the screen).
       
   694 	TRAP_IGNORE( 
       
   695 	    {
       
   696         if ( iVideoPlayer->VideoFrameRateL() == 0 && iVideoPlayer->VideoBitRateL() == 0 )
       
   697             {
       
   698             MSGMEDIACONTROLLOGGER_WRITE( "MsgVideoControl : no video stream" );
       
   699             
       
   700             // If both video frame rate and bit rate are zeros then we can be pretty
       
   701             // sure that there is no video stream on the file.
       
   702             iHasVideo = EFalse;
       
   703             }
       
   704                                                  
       
   705         iVideoPlayer->VideoFrameSizeL( iOriginalSize );
       
   706         } );
       
   707     
       
   708     HandleCallback( aError, EMsgAsyncControlStateReady );    
       
   709     
       
   710     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : MvpuoPrepareComplete()" );
       
   711     }
       
   712 
       
   713 // ---------------------------------------------------------
       
   714 // see MVideoPlayerUtilityObserver::MvpuoFrameReady
       
   715 // ---------------------------------------------------------
       
   716 //
       
   717 void CMsgVideoControl::MvpuoFrameReady( CFbsBitmap& /*aFrame*/,TInt /*aError*/ )
       
   718     {
       
   719     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : MvpuoFrameReady()" );
       
   720     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : MvpuoFrameReady()" );
       
   721     }
       
   722 
       
   723 // ---------------------------------------------------------
       
   724 // see MVideoPlayerUtilityObserver::MvpuoPlayComplete
       
   725 // Trapping callback as leaving not allowed.
       
   726 // ---------------------------------------------------------
       
   727 //
       
   728 void CMsgVideoControl::MvpuoPlayComplete( TInt aError )
       
   729     {
       
   730     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : MvpuoPlayComplete()" );
       
   731     
       
   732     // Enable backlight to turn on after video playback has ended.
       
   733     iTimer->Cancel();
       
   734     
       
   735     HandleCallback( aError, EMsgAsyncControlStateStopped );
       
   736     
       
   737     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : MvpuoPlayComplete()" );
       
   738     }
       
   739         
       
   740 // ---------------------------------------------------------
       
   741 // see MVideoPlayerUtilityObserver::MvpuoEvent
       
   742 // Trapping callback as leaving not allowed.
       
   743 // ---------------------------------------------------------
       
   744 //
       
   745 void CMsgVideoControl::MvpuoEvent( const TMMFEvent& /*aEvent*/ )
       
   746     {
       
   747     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : MvpuoEvent()" );
       
   748     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : MvpuoEvent()" );
       
   749     }
       
   750     
       
   751 // ---------------------------------------------------------
       
   752 // see MVideoLoadingObserver::MvloLoadingStarted
       
   753 // Trapping callback as leaving not allowed.
       
   754 // ---------------------------------------------------------
       
   755 //
       
   756 void CMsgVideoControl::MvloLoadingStarted()
       
   757     {
       
   758     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : MvloLoadingStarted()" );
       
   759 
       
   760     SetState( EMsgAsyncControlStateBuffering );
       
   761     
       
   762     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : MvloLoadingStarted()" );
       
   763     }
       
   764     
       
   765 // ---------------------------------------------------------
       
   766 // see MVideoLoadingObserver::MvloLoadingComplete
       
   767 // Trapping callback as leaving not allowed.
       
   768 // ---------------------------------------------------------
       
   769 //
       
   770 void CMsgVideoControl::MvloLoadingComplete()
       
   771     {
       
   772     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : MvloLoadingComplete()" );
       
   773     
       
   774     SetState( EMsgAsyncControlStatePlaying );
       
   775     
       
   776     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : MvloLoadingComplete()" );
       
   777     }
       
   778 
       
   779 // ---------------------------------------------------------
       
   780 // CMsgVideoControl::HandleCallback
       
   781 // ---------------------------------------------------------
       
   782 //
       
   783 void CMsgVideoControl::HandleCallback( TInt aError,
       
   784                                        TMsgAsyncControlState aNewState )
       
   785     {
       
   786     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : HandleCallback()" );
       
   787     MSGMEDIACONTROLLOGGER_WRITEF_ERROR_STATE( _L("CMsgVideoControl::HandleCallback: **aError: %d, CurrentState: %S"), aError, iState);
       
   788     MSGMEDIACONTROLLOGGER_WRITEF_ERROR_STATE( _L("CMsgVideoControl::HandleCallback: **aError: %d, aNewState: %S"), aError, aNewState);
       
   789     
       
   790     if ( aError == KErrMMPartialPlayback )
       
   791         {
       
   792         aError = KErrNone;
       
   793         }
       
   794     
       
   795     iError = aError;
       
   796     switch ( aError )
       
   797         {
       
   798         case KErrNone:    
       
   799             {
       
   800             SetState( aNewState );
       
   801             
       
   802             if ( iState == EMsgAsyncControlStateOpening )
       
   803                 {
       
   804                 if ( iVideoPlayer )
       
   805                     {
       
   806                     iVideoPlayer->Prepare();
       
   807                     }
       
   808                 }
       
   809             
       
   810             break;
       
   811             }
       
   812         case DRMCommon::EGeneralError:
       
   813         case DRMCommon::EUnknownMIME:
       
   814         case DRMCommon::EVersionNotSupported:
       
   815         case DRMCommon::ESessionError:
       
   816         case DRMCommon::ENoRights:
       
   817         case DRMCommon::ERightsDBCorrupted:
       
   818         case DRMCommon::EUnsupported:
       
   819         case DRMCommon::ERightsExpired:
       
   820         case DRMCommon::EInvalidRights:
       
   821             {
       
   822             SetState( EMsgAsyncControlStateNoRights );
       
   823             break;
       
   824             }
       
   825         case KErrNoMemory:
       
   826         default:
       
   827             {
       
   828             SetState( EMsgAsyncControlStateCorrupt );
       
   829             }
       
   830         } 
       
   831     
       
   832     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : HandleCallback()" );   
       
   833     }
       
   834 
       
   835 // ---------------------------------------------------------
       
   836 // CMsgVideoControl::Reset
       
   837 //
       
   838 // Empties the control.
       
   839 // ---------------------------------------------------------
       
   840 //
       
   841 void CMsgVideoControl::Close()
       
   842     {
       
   843     MSGMEDIACONTROLLOGGER_ENTERFN( "MsgVideoControl : Close()" );
       
   844     
       
   845     Reset();
       
   846     
       
   847     MSGMEDIACONTROLLOGGER_LEAVEFN( "MsgVideoControl : Close()" );   
       
   848     }
       
   849 
       
   850 
       
   851 // ---------------------------------------------------------
       
   852 // CMsgImageControl::HitRegionContains
       
   853 // 
       
   854 // Note! CONE will do final verification if control is really hit so
       
   855 //       not need to do it here.
       
   856 // ---------------------------------------------------------
       
   857 //
       
   858 #ifdef RD_SCALABLE_UI_V2
       
   859 TBool CMsgVideoControl::HitRegionContains( const TPoint& aPoint, 
       
   860                                            const CCoeControl& /*aControl*/ ) const
       
   861     {
       
   862     TBool result( EFalse );
       
   863     
       
   864     CCoeControl* visiblePlaceholder = VisiblePlaceholder();
       
   865     
       
   866     if ( visiblePlaceholder )
       
   867         {
       
   868         result = visiblePlaceholder->Rect().Contains( aPoint );
       
   869         }
       
   870     else
       
   871         {
       
   872         result = iVideoFrameArea.Contains( aPoint );;
       
   873         }
       
   874         
       
   875     return result;
       
   876     }
       
   877 #else
       
   878 TBool CMsgVideoControl::HitRegionContains( const TPoint& /*aPoint*/, 
       
   879                                            const CCoeControl& /*aControl*/ ) const
       
   880     {
       
   881     return EFalse;
       
   882     }
       
   883 
       
   884 #endif // RD_SCALABLE_UI_V2
       
   885 
       
   886 // ---------------------------------------------------------
       
   887 // CMsgVideoControl::HandleResourceChange
       
   888 //
       
   889 // Resets inactivity timer and prevents backlight from turning
       
   890 // off during video playback.
       
   891 // ---------------------------------------------------------
       
   892 //
       
   893 TInt CMsgVideoControl::DoResetInactivityTimer( TAny* /*aObject*/ )
       
   894     {
       
   895     User::ResetInactivityTime();
       
   896     return KErrNone;
       
   897     }
       
   898 
       
   899 // ---------------------------------------------------------
       
   900 // CMsgVideoControl::UpdateScaleFactorL
       
   901 // ---------------------------------------------------------
       
   902 //
       
   903 void CMsgVideoControl::UpdateScaleFactorL()
       
   904     {
       
   905     if ( iVideoPlayer )
       
   906         {
       
   907         TReal widthRatio = static_cast<TReal>( iSize.iWidth ) / 
       
   908                            static_cast<TReal>( iOriginalSize.iWidth );
       
   909         TReal heightRatio = static_cast<TReal>( iSize.iHeight ) / 
       
   910                             static_cast<TReal>( iOriginalSize.iHeight );
       
   911                         
       
   912         iScaleFactor = widthRatio < heightRatio ? widthRatio : 
       
   913                                                   heightRatio;
       
   914         }
       
   915     }
       
   916 
       
   917 //  End of File