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