videoplayback/videoplaybackview/viewsrc/mpxvideoplaybackdisplayhandler.cpp
changeset 44 518105d52e45
child 50 21fe8338c6bf
equal deleted inserted replaced
42:17f382c040b1 44:518105d52e45
       
     1 /*
       
     2 * Copyright (c) 2009 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 playback display handler
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version:  ou1cpsw#27 %
       
    19 
       
    20 #include <sysutil.h>
       
    21 #include <s32file.h>
       
    22 #include <mpxcommand.h>
       
    23 #include <mpxcommandgeneraldefs.h>
       
    24 #include <mpxplaybackutility.h>
       
    25 #include <mpxvideoplaybackdefs.h>
       
    26 
       
    27 #include "mpxvideocontainer.h"
       
    28 #include "mpxvideoviewwrapper.h"
       
    29 #include "mpxvideoplaybackdisplayhandler.h"
       
    30 #include "mpxvideoregion.h"
       
    31 #include "videoplaybackviewfiledetails.h"
       
    32 
       
    33 const TInt KVIDEORESIZINGREPEATRATE = 50000;
       
    34 const TReal32 KTRANSITIONEFFECTCNT = 8;
       
    35 
       
    36 _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" );
       
    37 
       
    38 
       
    39 CMPXVideoPlaybackDisplayHandler::CMPXVideoPlaybackDisplayHandler( MMPXPlaybackUtility* aPlayUtil,
       
    40                                                                   CMPXVideoViewWrapper* aViewWrapper )
       
    41     : iPlaybackUtility( aPlayUtil )
       
    42     , iTransitionEffectCnt( 0 )
       
    43     , iViewWrapper( aViewWrapper )
       
    44     , iScaleWidth( 100.0f )
       
    45     , iScaleHeight( 100.0f )
       
    46     , iHorizontalPosition( EHorizontalAlignCenter )
       
    47     , iVerticalPosition( EVerticalAlignCenter )
       
    48     , iRotation( EVideoRotationNone )
       
    49     , iAutoScale( EAutoScaleBestFit )
       
    50 {
       
    51 }
       
    52 
       
    53 CMPXVideoPlaybackDisplayHandler::~CMPXVideoPlaybackDisplayHandler()
       
    54 {
       
    55     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::~CMPXVideoPlaybackDisplayHandler()"));
       
    56 
       
    57     MPX_TRAPD( error, SaveAspectRatioL() );
       
    58 
       
    59     if ( iResizingTimer )
       
    60     {
       
    61         iResizingTimer->Cancel();
       
    62         delete iResizingTimer;
       
    63         iResizingTimer = NULL;
       
    64     }
       
    65 
       
    66     iAspectRatioArray.Close();
       
    67 
       
    68     if ( iVideoDisplay )
       
    69     {
       
    70         SurfaceRemoved();
       
    71 
       
    72         delete iVideoDisplay;
       
    73         iVideoDisplay = NULL;
       
    74     }
       
    75 
       
    76 	if ( iVideoContainer )
       
    77     {
       
    78         delete iVideoContainer;
       
    79         iVideoContainer = NULL;
       
    80     }
       
    81 }
       
    82 
       
    83 CMPXVideoPlaybackDisplayHandler*
       
    84 CMPXVideoPlaybackDisplayHandler::NewL( MMPXPlaybackUtility* aPlayUtil,
       
    85                                        CMPXVideoViewWrapper* aViewWrapper )
       
    86 {
       
    87     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::NewL()"));
       
    88 
       
    89     CMPXVideoPlaybackDisplayHandler* self =
       
    90         new(ELeave) CMPXVideoPlaybackDisplayHandler( aPlayUtil, aViewWrapper );
       
    91 
       
    92     CleanupStack::PushL( self );
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop();
       
    95     return self;
       
    96 }
       
    97 
       
    98 // -------------------------------------------------------------------------------------------------
       
    99 //  CMPXVideoPlaybackDisplayHandler::ConstructL()
       
   100 // -------------------------------------------------------------------------------------------------
       
   101 //
       
   102 void CMPXVideoPlaybackDisplayHandler::ConstructL()
       
   103 {
       
   104     iResizingTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   105     LoadAspectRatioL();
       
   106 }
       
   107 
       
   108 // -------------------------------------------------------------------------------------------------
       
   109 //   CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()
       
   110 // -------------------------------------------------------------------------------------------------
       
   111 //
       
   112 void CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL(
       
   113                                           RWsSession& /*aWs*/,
       
   114                                           CWsScreenDevice& aScreenDevice,
       
   115                                           RWindow& aWin,
       
   116                                           TRect aDisplayRect )
       
   117 {
       
   118     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()"));
       
   119 
       
   120     if ( ! iVideoContainer )
       
   121     {
       
   122         iVideoContainer = new ( ELeave ) CMPXVideoContainer();
       
   123         iVideoContainer->ConstructL();
       
   124         iVideoContainer->SetRect( aDisplayRect );
       
   125     }
       
   126 
       
   127     aWin.SetSurfaceTransparency( ETrue );
       
   128 
       
   129     RWindowBase *videoWindow = iVideoContainer->DrawableWindow();
       
   130     videoWindow->SetOrdinalPosition( -1 );
       
   131     (&aWin)->SetOrdinalPosition( 0 );
       
   132 
       
   133     MPX_DEBUG(_L("VideoWindow ordinal position is: %d"), videoWindow->OrdinalPosition());
       
   134     MPX_DEBUG(_L("UiWindow ordinal position is: %d"), (&aWin)->OrdinalPosition());
       
   135 
       
   136     AddDisplayWindowL( aScreenDevice, *videoWindow, (RWindow*)videoWindow );
       
   137 }
       
   138 
       
   139 // -------------------------------------------------------------------------------------------------
       
   140 //   CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()
       
   141 // -------------------------------------------------------------------------------------------------
       
   142 //
       
   143 void CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()
       
   144 {
       
   145     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()"));
       
   146 
       
   147     if ( iVideoDisplay )
       
   148     {
       
   149         SurfaceRemoved();
       
   150         delete iVideoDisplay;
       
   151         iVideoDisplay = NULL;
       
   152     }
       
   153 
       
   154     if ( iVideoContainer )
       
   155     {
       
   156         delete iVideoContainer;
       
   157         iVideoContainer = NULL;
       
   158     }
       
   159 
       
   160     iSurfaceId = TSurfaceId::CreateNullId();
       
   161 }
       
   162 
       
   163 // -------------------------------------------------------------------------------------------------
       
   164 //   CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL()
       
   165 // -------------------------------------------------------------------------------------------------
       
   166 //
       
   167 void CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL( CMPXMessage* aMessage )
       
   168 {
       
   169     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessage()"));
       
   170 
       
   171     TMPXVideoDisplayCommand message =
       
   172         ( *(aMessage->Value<TMPXVideoDisplayCommand>(KMPXMediaVideoDisplayCommand)) );
       
   173 
       
   174     MPX_DEBUG(
       
   175       _L("CMPXVideoPlaybackDisplayHandler::HandleVideoDisplayMessageL() message = %d"), message );
       
   176 
       
   177     switch ( message )
       
   178     {
       
   179         case EPbMsgVideoSurfaceCreated:
       
   180         {
       
   181             SurfaceCreatedL( aMessage );
       
   182             break;
       
   183         }
       
   184         case EPbMsgVideoSurfaceChanged:
       
   185         {
       
   186             SurfaceChangedL( aMessage );
       
   187             break;
       
   188         }
       
   189         case EPbMsgVideoSurfaceRemoved:
       
   190         {
       
   191             SurfaceRemoved();
       
   192             break;
       
   193         }
       
   194     }
       
   195 }
       
   196 
       
   197 
       
   198 // -------------------------------------------------------------------------------------------------
       
   199 //   CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()
       
   200 // -------------------------------------------------------------------------------------------------
       
   201 //
       
   202 TInt CMPXVideoPlaybackDisplayHandler::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd )
       
   203 {
       
   204     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()"));
       
   205 
       
   206     TInt aspectRatio;
       
   207 
       
   208     aspectRatio = SetNgaAspectRatioL( aCmd );
       
   209 
       
   210     //
       
   211     //  Update the aspect ratio in the array
       
   212     //
       
   213     TInt count = iAspectRatioArray.Count();
       
   214 
       
   215     if ( count > 0 && count > iCurrentIndexForAspectRatio )
       
   216     {
       
   217         iAspectRatioArray[iCurrentIndexForAspectRatio].scalingType = (TMMFScalingType)aspectRatio;
       
   218     }
       
   219 
       
   220     return aspectRatio;
       
   221 }
       
   222 
       
   223 // -------------------------------------------------------------------------------------------------
       
   224 //   CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL
       
   225 // -------------------------------------------------------------------------------------------------
       
   226 //
       
   227 TInt CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL(
       
   228         VideoPlaybackViewFileDetails* aFileDetails, TReal32 aDisplayAspectRatio )
       
   229 {
       
   230     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL()"));
       
   231 
       
   232     TInt newAspectRatio = EMMFNatural;
       
   233 
       
   234     if ( aFileDetails->mVideoHeight > 0 && aFileDetails->mVideoWidth > 0 )
       
   235     {
       
   236         TMMFScalingType scalingType = EMMFNatural;
       
   237 
       
   238         TReal32 videoAspectRatio = (TReal32)aFileDetails->mVideoWidth /
       
   239                                    (TReal32)aFileDetails->mVideoHeight;
       
   240 
       
   241         TInt cnt = iAspectRatioArray.Count();
       
   242         TInt i = 0;
       
   243 
       
   244         //
       
   245         //  check whether dat file has the information about (videoRatio + screenRatio)
       
   246         //
       
   247         for ( ; i < cnt ; i++ )
       
   248         {
       
   249             if ( iAspectRatioArray[i].videoRatio == videoAspectRatio &&
       
   250                  iAspectRatioArray[i].screenRatio == aDisplayAspectRatio &&
       
   251                  ( scalingType = iAspectRatioArray[i].scalingType ) > 0 )
       
   252             {
       
   253                 break;
       
   254             }
       
   255         }
       
   256 
       
   257         //
       
   258         //  if can't find out match aspect ratio in dat file,
       
   259         //  choose the scaling type through the rule
       
   260         //      aspectRatioDiff =  videoAspectRatio - aDisplayAspectRatio
       
   261         //      aspectRatioDiff ==  0        ==> natural
       
   262         //      aspectRatioDiff > 0.1        ==> zoom
       
   263         //      aspectRatioDiff < - 0.3      ==> natural
       
   264         //      aspectRatioDiff >= - 0.3 and <= 0.1   ==> stretch
       
   265         //
       
   266 
       
   267         if ( i == cnt )
       
   268         {
       
   269             if ( videoAspectRatio - aDisplayAspectRatio > 0.1 )
       
   270             {
       
   271                 scalingType = EMMFZoom;
       
   272             }
       
   273             else if ( ( videoAspectRatio != aDisplayAspectRatio ) &&
       
   274                       ( videoAspectRatio - aDisplayAspectRatio > (- 0.3) ) )
       
   275             {
       
   276                 scalingType = EMMFStretch;
       
   277             }
       
   278 
       
   279             TMPXAspectRatio ratio;
       
   280 
       
   281             ratio.videoRatio = videoAspectRatio;
       
   282             ratio.screenRatio = aDisplayAspectRatio;
       
   283             ratio.scalingType = scalingType;
       
   284 
       
   285             iAspectRatioArray.Append( ratio );
       
   286         }
       
   287 
       
   288         iCurrentIndexForAspectRatio = i;
       
   289 
       
   290         TMPXVideoPlaybackCommand aspectRatioCmd = EPbCmdNaturalAspectRatio;
       
   291 
       
   292         if ( scalingType == EMMFZoom )
       
   293         {
       
   294             aspectRatioCmd = EPbCmdZoomAspectRatio;
       
   295         }
       
   296         else if ( scalingType == EMMFStretch )
       
   297         {
       
   298             aspectRatioCmd = EPbCmdStretchAspectRatio;
       
   299         }
       
   300 
       
   301         newAspectRatio = SetAspectRatioL( aspectRatioCmd );
       
   302     }
       
   303 
       
   304     return newAspectRatio;
       
   305 }
       
   306 
       
   307 // -------------------------------------------------------------------------------------------------
       
   308 //   CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL
       
   309 // -------------------------------------------------------------------------------------------------
       
   310 //
       
   311 void CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL()
       
   312 {
       
   313     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL"));
       
   314 
       
   315     RFs fs;
       
   316     TInt err = fs.Connect();
       
   317     CleanupClosePushL<RFs>( fs );
       
   318 
       
   319     TBool canSave = EFalse;
       
   320 
       
   321     TRAP_IGNORE( canSave = ! SysUtil::FFSSpaceBelowCriticalLevelL(
       
   322                                  &fs, sizeof(TMPXAspectRatio) * iAspectRatioArray.Count()) );
       
   323 
       
   324     if ( canSave )
       
   325     {
       
   326         // save list to disk
       
   327         RFileWriteStream out;
       
   328 
       
   329         TInt err( out.Replace( fs, KAspectRatioFile, EFileWrite ) );
       
   330 
       
   331         if ( err == KErrPathNotFound )
       
   332         {
       
   333             fs.MkDirAll( KAspectRatioFile );
       
   334             err = out.Create( fs, KAspectRatioFile, EFileWrite );
       
   335         }
       
   336 
       
   337         if ( ! err )
       
   338         {
       
   339             TInt cnt = iAspectRatioArray.Count();
       
   340 
       
   341             MPX_TRAP( err,
       
   342             {
       
   343                 for ( TInt i = 0 ; i < cnt ; i++ )
       
   344                 {
       
   345                     //Save (videoRatio + screenRatio + scalingType)
       
   346                     out.WriteReal32L( iAspectRatioArray[i].videoRatio );
       
   347                     out.WriteReal32L( iAspectRatioArray[i].screenRatio );
       
   348                     out.WriteInt8L( iAspectRatioArray[i].scalingType );
       
   349                 }
       
   350             } );
       
   351 
       
   352             out.Close();
       
   353         }
       
   354     }
       
   355 
       
   356     CleanupStack::PopAndDestroy();
       
   357 }
       
   358 
       
   359 // -------------------------------------------------------------------------------------------------
       
   360 //   CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL
       
   361 // -------------------------------------------------------------------------------------------------
       
   362 //
       
   363 void CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL()
       
   364 {
       
   365     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::LoadAspectRatioL()"));
       
   366 
       
   367     RFs fs;
       
   368     RFileReadStream in;
       
   369 
       
   370     TInt err = fs.Connect();
       
   371     CleanupClosePushL<RFs>( fs );
       
   372 
       
   373     if ( ! err && in.Open( fs, KAspectRatioFile, EFileRead ) == KErrNone )
       
   374     {
       
   375         TMPXAspectRatio ratio;
       
   376 
       
   377         MPX_TRAP( err,
       
   378         {
       
   379             for ( err = KErrNone ; err == KErrNone ; )
       
   380             {
       
   381                 //
       
   382                 //  Read (videoRatio + screenRatio + scalingType)
       
   383                 //
       
   384                 ratio.videoRatio = in.ReadReal32L();
       
   385                 ratio.screenRatio = in.ReadReal32L();
       
   386                 ratio.scalingType = (TMMFScalingType)in.ReadInt8L();
       
   387 
       
   388                 iAspectRatioArray.Append( ratio );
       
   389             }
       
   390         } );
       
   391 
       
   392         in.Close();
       
   393     }
       
   394 
       
   395     CleanupStack::PopAndDestroy();
       
   396 }
       
   397 
       
   398 // -------------------------------------------------------------------------------------------------
       
   399 //   CMPXVideoPlaybackDisplayHandler::UpdateVideoRectL()
       
   400 // -------------------------------------------------------------------------------------------------
       
   401 //
       
   402 void CMPXVideoPlaybackDisplayHandler::UpdateVideoRectL( TRect aClipRect, TBool transitionEffect )
       
   403 {
       
   404     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::UpdateVideoRectL()"));
       
   405 
       
   406     if ( transitionEffect )
       
   407     {
       
   408         iTlXDiff = (TReal32)( iWindowRect.iTl.iX - aClipRect.iTl.iX ) / KTRANSITIONEFFECTCNT;
       
   409         iTlYDiff = (TReal32)( iWindowRect.iTl.iY - aClipRect.iTl.iY ) / KTRANSITIONEFFECTCNT;
       
   410         iBrXDiff = (TReal32)( iWindowRect.iBr.iX - aClipRect.iBr.iX ) / KTRANSITIONEFFECTCNT;
       
   411         iBrYDiff = (TReal32)( iWindowRect.iBr.iY - aClipRect.iBr.iY ) / KTRANSITIONEFFECTCNT;
       
   412 
       
   413         if ( iResizingTimer->IsActive() )
       
   414         {
       
   415             iResizingTimer->Cancel();
       
   416         }
       
   417 
       
   418         iResizingTimer->Start(
       
   419                 0,
       
   420                 KVIDEORESIZINGREPEATRATE,
       
   421                 TCallBack( CMPXVideoPlaybackDisplayHandler::UpdateVideoRectTimeOutL, this ) );
       
   422     }
       
   423     else
       
   424     {
       
   425         SetVideoRectL( aClipRect );
       
   426 
       
   427         iWindowRect = aClipRect;
       
   428 
       
   429         iViewWrapper->UpdateVideoRectDone();
       
   430     }
       
   431 }
       
   432 
       
   433 // -------------------------------------------------------------------------------------------------
       
   434 //   CMPXVideoPlaybackDisplayHandler::UpdateVideoRectTimeOutL()
       
   435 // -------------------------------------------------------------------------------------------------
       
   436 //
       
   437 TInt CMPXVideoPlaybackDisplayHandler::UpdateVideoRectTimeOutL( TAny* aPtr )
       
   438 {
       
   439     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::UpdateVideoRectTimeOutL()"));
       
   440 
       
   441     static_cast<CMPXVideoPlaybackDisplayHandler*>(aPtr)->CalculateVideoRectL();
       
   442 
       
   443     return KErrNone;
       
   444 }
       
   445 
       
   446 // -------------------------------------------------------------------------------------------------
       
   447 //   CMPXVideoPlaybackDisplayHandler::CalculateVideoRectL()
       
   448 // -------------------------------------------------------------------------------------------------
       
   449 //
       
   450 void CMPXVideoPlaybackDisplayHandler::CalculateVideoRectL()
       
   451 {
       
   452     iTransitionEffectCnt++;
       
   453 
       
   454     TRect windowRect( (TInt)( (TReal32)iWindowRect.iTl.iX - iTlXDiff * (TReal32)iTransitionEffectCnt ),
       
   455                       (TInt)( (TReal32)iWindowRect.iTl.iY - iTlYDiff * (TReal32)iTransitionEffectCnt ),
       
   456                       (TInt)( (TReal32)iWindowRect.iBr.iX - iBrXDiff * (TReal32)iTransitionEffectCnt ),
       
   457                       (TInt)( (TReal32)iWindowRect.iBr.iY - iBrYDiff * (TReal32)iTransitionEffectCnt ) );
       
   458 
       
   459     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateVideoRectL() %d %d %d %d"),
       
   460             windowRect.iTl.iX, windowRect.iTl.iY, windowRect.iBr.iX, windowRect.iBr.iY );
       
   461 
       
   462     SetVideoRectL( windowRect );
       
   463 
       
   464     if ( iTransitionEffectCnt >= KTRANSITIONEFFECTCNT )
       
   465     {
       
   466         iTransitionEffectCnt = 0;
       
   467         iWindowRect = windowRect;
       
   468 
       
   469         if ( iResizingTimer->IsActive() )
       
   470         {
       
   471             iResizingTimer->Cancel();
       
   472         }
       
   473 
       
   474         MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateVideoRectL() Done"));
       
   475 
       
   476         iViewWrapper->UpdateVideoRectDone();
       
   477     }
       
   478 }
       
   479 
       
   480 // -------------------------------------------------------------------------------------------------
       
   481 //   CMPXVideoPlaybackDisplayHandler::SetVideoRectL()
       
   482 // -------------------------------------------------------------------------------------------------
       
   483 //
       
   484 void CMPXVideoPlaybackDisplayHandler::SetVideoRectL( TRect aRect )
       
   485 {
       
   486     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetVideoRectL()"));
       
   487 
       
   488     if ( iVideoDisplay )
       
   489     {
       
   490         iVideoDisplay->SetVideoExtentL( *iWindowBase, aRect, TRect( iWindowBase->Size() ) );
       
   491     }
       
   492 }
       
   493 
       
   494 // -------------------------------------------------------------------------------------------------
       
   495 //   CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL()
       
   496 // -------------------------------------------------------------------------------------------------
       
   497 //
       
   498 void CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL( CWsScreenDevice& aScreenDevice,
       
   499                                                          RWindowBase& aWindowBase,
       
   500                                                          RWindow* aWin )
       
   501 {
       
   502     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL()"));
       
   503 
       
   504     iWindowBase = &aWindowBase;
       
   505 
       
   506     TInt displayId = aScreenDevice.GetScreenNumber();
       
   507 
       
   508     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() displayId %d"), displayId);
       
   509 
       
   510     CMediaClientVideoDisplay* tempDisplay = iVideoDisplay;
       
   511 
       
   512     iVideoDisplay = CMediaClientVideoDisplay::NewL( displayId );
       
   513 
       
   514     delete tempDisplay;
       
   515 
       
   516     TRect cropRect = TRect( aWin->Size() );
       
   517 
       
   518     //
       
   519     // If RWindow is still in potrait, rotate surface to play a video in landscape
       
   520     //
       
   521     if ( cropRect.Width() < cropRect.Height() )
       
   522     {
       
   523         iRotation = EVideoRotationClockwise90;
       
   524     }
       
   525 
       
   526     iWindowRect = cropRect;
       
   527 
       
   528     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() cropRect (%d, %d), (%d, %d)"),
       
   529         cropRect.iTl.iX, cropRect.iTl.iY, cropRect.iBr.iX, cropRect.iBr.iY);
       
   530 
       
   531     MPX_TRAPD( dispError,
       
   532     iVideoDisplay->AddDisplayWindowL( iWindowBase,
       
   533                                       cropRect,
       
   534                                       cropRect,
       
   535                                       cropRect,
       
   536                                       iScaleWidth,
       
   537                                       iScaleHeight,
       
   538                                       iRotation,
       
   539                                       iAutoScale,
       
   540                                       iHorizontalPosition,
       
   541                                       iVerticalPosition,
       
   542                                       aWin );
       
   543     );
       
   544 
       
   545     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() Display Added"));
       
   546     //
       
   547     //  Check if surface was created before window was ready
       
   548     //
       
   549     if ( iSurfaceCached )
       
   550     {
       
   551         iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect );
       
   552 
       
   553         iSurfaceCached = EFalse;
       
   554     }
       
   555 }
       
   556 
       
   557 // -------------------------------------------------------------------------------------------------
       
   558 //   CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL()
       
   559 // -------------------------------------------------------------------------------------------------
       
   560 //
       
   561 void CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL( CMPXMessage* aMessage )
       
   562 {
       
   563     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL()"));
       
   564 
       
   565     TSurfaceId oldSurfaceId = iSurfaceId;
       
   566 
       
   567     //
       
   568     //  Extract the surface parameters from the message
       
   569     //
       
   570     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
       
   571     iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
       
   572     iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
       
   573 
       
   574     if ( iVideoDisplay )
       
   575     {
       
   576         //
       
   577         //  Remove old surface if one exists
       
   578         //
       
   579         if ( ! oldSurfaceId.IsNull() )
       
   580         {
       
   581             iVideoDisplay->RemoveSurface();
       
   582         }
       
   583 
       
   584         //
       
   585         //  Add new surface
       
   586         //
       
   587         iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect );
       
   588     }
       
   589     else
       
   590     {
       
   591         //
       
   592         //  Video display has not been created yet, save surface information to create
       
   593         //  the surface when the display is created
       
   594         //
       
   595         iSurfaceCached = ETrue;
       
   596     }
       
   597 }
       
   598 
       
   599 // -------------------------------------------------------------------------------------------------
       
   600 //   CMPXVideoPlaybackDisplayHandler::SurfaceChangedL()
       
   601 // -------------------------------------------------------------------------------------------------
       
   602 //
       
   603 void CMPXVideoPlaybackDisplayHandler::SurfaceChangedL( CMPXMessage* aMessage )
       
   604 {
       
   605     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceChangedL()"));
       
   606 
       
   607     //
       
   608     //  Extract the surface parameters from the message
       
   609     //
       
   610     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
       
   611     iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
       
   612     iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
       
   613 
       
   614     if ( iVideoDisplay )
       
   615     {
       
   616         //
       
   617         //  Add new surface
       
   618         //
       
   619         iVideoDisplay->SurfaceParametersChanged( iSurfaceId, iCropRect, iAspectRatio );
       
   620 
       
   621         iVideoDisplay->RedrawWindows( iCropRect );
       
   622     }
       
   623 }
       
   624 
       
   625 // -------------------------------------------------------------------------------------------------
       
   626 //   CMPXVideoPlaybackDisplayHandler::SurfaceRemoved()
       
   627 // -------------------------------------------------------------------------------------------------
       
   628 //
       
   629 void CMPXVideoPlaybackDisplayHandler::SurfaceRemoved()
       
   630 {
       
   631     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceRemoved()"));
       
   632 
       
   633     if ( iVideoDisplay )
       
   634     {
       
   635         iVideoDisplay->RemoveSurface();
       
   636     }
       
   637 
       
   638     iSurfaceId = TSurfaceId::CreateNullId();
       
   639 }
       
   640 
       
   641 // -------------------------------------------------------------------------------------------------
       
   642 //   CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL()
       
   643 // -------------------------------------------------------------------------------------------------
       
   644 //
       
   645 TInt CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL( TMPXVideoPlaybackCommand aCmd )
       
   646 {
       
   647     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL()"));
       
   648 
       
   649     TInt aspectRatio = EMMFNatural;
       
   650 
       
   651     switch ( aCmd )
       
   652     {
       
   653         case EPbCmdNaturalAspectRatio:
       
   654         {
       
   655             iAutoScale = EAutoScaleBestFit;
       
   656             aspectRatio = EMMFNatural;
       
   657             break;
       
   658         }
       
   659         case EPbCmdZoomAspectRatio:
       
   660         {
       
   661             iAutoScale = EAutoScaleClip;
       
   662             aspectRatio = EMMFZoom;
       
   663             break;
       
   664         }
       
   665         case EPbCmdStretchAspectRatio:
       
   666         {
       
   667             iAutoScale = EAutoScaleStretch;
       
   668             aspectRatio = EMMFStretch;
       
   669             break;
       
   670         }
       
   671     }
       
   672 
       
   673     if ( iVideoDisplay && ! iSurfaceId.IsNull() )
       
   674     {
       
   675         iVideoDisplay->SetAutoScaleL( iAutoScale,
       
   676                                       iHorizontalPosition,
       
   677                                       iVerticalPosition,
       
   678                                       iCropRect );
       
   679     }
       
   680 
       
   681     return aspectRatio;
       
   682 }
       
   683 
       
   684 // End of File