videoplayback/videoplaybackviews/src/mpxvideoplaybackdisplayhandler.cpp
branchRCL_3
changeset 21 315810614048
parent 20 2d690156cf8f
equal deleted inserted replaced
20:2d690156cf8f 21:315810614048
    14 * Description:   Implementation of video playback display handler
    14 * Description:   Implementation of video playback display handler
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // Version : %version: 15 %
    19 // Version : %version: 17 %
    20 
    20 
    21 
    21 
    22 #include <sysutil.h>
    22 #include <sysutil.h>
    23 #include <s32file.h>
    23 #include <s32file.h>
    24 #include <mpxcommand.h>
    24 #include <mpxcommand.h>
    25 #include <mpxcommandgeneraldefs.h>
    25 #include <mpxcommandgeneraldefs.h>
    26 #include <mpxplaybackutility.h>
    26 #include <mpxplaybackutility.h>
       
    27 #include <mpxvideoplaybackdefs.h>
    27 
    28 
    28 #include "mpxvideoplaybackdisplayhandler.h"
    29 #include "mpxvideoplaybackdisplayhandler.h"
    29 #include "mpxvideoregion.h"
    30 #include "mpxvideoregion.h"
    30 #include "mpxvideoplaybackviewfiledetails.h"
    31 #include "mpxvideoplaybackviewfiledetails.h"
    31 #include "mpxvideoplaybackcontainer.h"
    32 #include "mpxvideoplaybackcontainer.h"
    32 #include "mpxcommonvideoplaybackview.hrh"
    33 #include "mpxcommonvideoplaybackview.hrh"
    33 #include <mpxvideoplaybackdefs.h>
       
    34 
    34 
    35 
    35 
    36 _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" );
    36 _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" );
    37 
    37 
    38 
    38 
    39 CMPXVideoPlaybackDisplayHandler::CMPXVideoPlaybackDisplayHandler(
    39 CMPXVideoPlaybackDisplayHandler::CMPXVideoPlaybackDisplayHandler(
    40                                      MMPXPlaybackUtility* aPlayUtil,
    40                                      MMPXPlaybackUtility* aPlayUtil,
    41                                      CMPXVideoPlaybackContainer* aContainer)
    41                                      CMPXVideoPlaybackContainer* aContainer)
    42     : iPlaybackUtility( aPlayUtil )
    42     : iPlaybackUtility( aPlayUtil )
    43     , iContainer( aContainer )
    43     , iContainer( aContainer )
    44 #ifdef SYMBIAN_BUILD_GCE
       
    45     , iScaleWidth( 100.0f )
    44     , iScaleWidth( 100.0f )
    46     , iScaleHeight( 100.0f )
    45     , iScaleHeight( 100.0f )
    47     , iHorizontalPosition( EHorizontalAlignCenter )
    46     , iHorizontalPosition( EHorizontalAlignCenter )
    48     , iVerticalPosition( EVerticalAlignCenter )
    47     , iVerticalPosition( EVerticalAlignCenter )
    49     , iRotation( EVideoRotationNone )
    48     , iRotation( EVideoRotationNone )
    50     , iAutoScale( EAutoScaleBestFit )
    49     , iAutoScale( EAutoScaleBestFit )
    51 #endif
       
    52 {
    50 {
    53 }
    51 }
    54 
    52 
    55 CMPXVideoPlaybackDisplayHandler::~CMPXVideoPlaybackDisplayHandler()
    53 CMPXVideoPlaybackDisplayHandler::~CMPXVideoPlaybackDisplayHandler()
    56 {
    54 {
    58 
    56 
    59     MPX_TRAPD( error, SaveAspectRatioL() );
    57     MPX_TRAPD( error, SaveAspectRatioL() );
    60 
    58 
    61     iAspectRatioArray.Close();
    59     iAspectRatioArray.Close();
    62 
    60 
    63 #ifdef SYMBIAN_BUILD_GCE
       
    64     if ( iVideoDisplay )
    61     if ( iVideoDisplay )
    65     {
    62     {
    66         delete iVideoDisplay;
    63         delete iVideoDisplay;
    67         iVideoDisplay = NULL;
    64         iVideoDisplay = NULL;
    68     }
    65     }
    69 #endif
       
    70 
    66 
    71     iSurfaceId = TSurfaceId::CreateNullId();
    67     iSurfaceId = TSurfaceId::CreateNullId();
    72 }
    68 }
    73 
    69 
    74 CMPXVideoPlaybackDisplayHandler*
    70 CMPXVideoPlaybackDisplayHandler*
    85     CleanupStack::Pop();
    81     CleanupStack::Pop();
    86     return self;
    82     return self;
    87 }
    83 }
    88 
    84 
    89 // -------------------------------------------------------------------------------------------------
    85 // -------------------------------------------------------------------------------------------------
    90 //  CMPXVideoPlaybackDisplayHandler::ConstructL()
    86 //   CMPXVideoPlaybackDisplayHandler::ConstructL()
    91 // -------------------------------------------------------------------------------------------------
    87 // -------------------------------------------------------------------------------------------------
    92 //
    88 //
    93 void CMPXVideoPlaybackDisplayHandler::ConstructL()
    89 void CMPXVideoPlaybackDisplayHandler::ConstructL()
    94 {
    90 {
    95     LoadAspectRatioL();
    91     LoadAspectRatioL();
       
    92 
       
    93     TRect displayRect = iContainer->Rect();
       
    94     iDisplayAspectRatio = (TReal32)displayRect.Width() / (TReal32)displayRect.Height();
       
    95 
       
    96     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::ConstructL() iDisplayAspectRatio = %f"),
       
    97         iDisplayAspectRatio );
    96 }
    98 }
    97 
    99 
    98 // -------------------------------------------------------------------------------------------------
   100 // -------------------------------------------------------------------------------------------------
    99 //   CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()
   101 //   CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()
   100 // -------------------------------------------------------------------------------------------------
   102 // -------------------------------------------------------------------------------------------------
   101 //
   103 //
   102 void CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL( CWsScreenDevice& aScreenDevice,
   104 void CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL(
   103                                                             RWindow& aWin )
   105                                            CWsScreenDevice& aScreenDevice,
       
   106                                            RWindow& aWin,
       
   107                                            CMPXVideoPlaybackViewFileDetails* aFileDetails )
   104 {
   108 {
   105     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()"));
   109     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()"));
   106 
   110 
   107 #ifdef SYMBIAN_BUILD_GCE
   111     //
       
   112     //  Save off the video aspect ratio
       
   113     //
       
   114     iVideoHeight = aFileDetails->iVideoHeight;
       
   115     iVideoWidth  = aFileDetails->iVideoWidth;
       
   116 
       
   117     MPX_DEBUG(
       
   118         _L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL() clip size (%d,%d)"),
       
   119                 iVideoHeight, iVideoWidth );
       
   120 
   108     AddDisplayWindowL( aScreenDevice, aWin, &aWin );
   121     AddDisplayWindowL( aScreenDevice, aWin, &aWin );
   109 #endif
       
   110 }
   122 }
   111 
   123 
   112 // -------------------------------------------------------------------------------------------------
   124 // -------------------------------------------------------------------------------------------------
   113 //   CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()
   125 //   CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()
   114 // -------------------------------------------------------------------------------------------------
   126 // -------------------------------------------------------------------------------------------------
   115 //
   127 //
   116 void CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()
   128 void CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()
   117 {
   129 {
   118     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()"));
   130     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()"));
   119 
   131 
   120 #ifdef SYMBIAN_BUILD_GCE
       
   121     if ( iVideoDisplay )
   132     if ( iVideoDisplay )
   122     {
   133     {
   123         //
   134         //
   124         //  Surface is being removed, signal the container so it can reset the background
   135         //  Surface is being removed, signal the container so it can reset the background
   125         //
   136         //
   129         }
   140         }
   130 
   141 
   131         delete iVideoDisplay;
   142         delete iVideoDisplay;
   132         iVideoDisplay = NULL;
   143         iVideoDisplay = NULL;
   133     }
   144     }
   134 #endif
       
   135 
   145 
   136     iSurfaceId = TSurfaceId::CreateNullId();
   146     iSurfaceId = TSurfaceId::CreateNullId();
   137 }
   147 }
   138 
   148 
   139 // -------------------------------------------------------------------------------------------------
   149 // -------------------------------------------------------------------------------------------------
   148     TMPXVideoDisplayCommand message =
   158     TMPXVideoDisplayCommand message =
   149         ( *(aMessage->Value<TMPXVideoDisplayCommand>(KMPXMediaVideoDisplayCommand)) );
   159         ( *(aMessage->Value<TMPXVideoDisplayCommand>(KMPXMediaVideoDisplayCommand)) );
   150 
   160 
   151     switch ( message )
   161     switch ( message )
   152     {
   162     {
   153 #ifdef SYMBIAN_BUILD_GCE
       
   154         case EPbMsgVideoSurfaceCreated:
   163         case EPbMsgVideoSurfaceCreated:
   155         {
   164         {
   156             MPX_DEBUG(_L(" message = EPbMsgVideoSurfaceCreated"));
       
   157             SurfaceCreatedL( aMessage );
   165             SurfaceCreatedL( aMessage );
   158             break;
   166             break;
   159         }
   167         }
   160         case EPbMsgVideoSurfaceChanged:
   168         case EPbMsgVideoSurfaceChanged:
   161         {
   169         {
   162             MPX_DEBUG(_L(" message = EPbMsgVideoSurfaceChanged"));
       
   163             SurfaceChangedL( aMessage );
   170             SurfaceChangedL( aMessage );
   164             break;
   171             break;
   165         }
   172         }
   166         case EPbMsgVideoSurfaceRemoved:
   173         case EPbMsgVideoSurfaceRemoved:
   167         {
   174         {
   168             MPX_DEBUG(_L(" message = EPbMsgVideoSurfaceRemoved"));
       
   169             SurfaceRemoved();
   175             SurfaceRemoved();
   170             break;
   176             break;
   171         }
   177         }
   172 #endif
   178     }
   173     }
   179 }
   174 }
   180 
   175 
   181 // -------------------------------------------------------------------------------------------------
   176 // -------------------------------------------------------------------------------------------------
   182 //   CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL
   177 //   CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()
   183 // -------------------------------------------------------------------------------------------------
   178 // -------------------------------------------------------------------------------------------------
   184 //
   179 //
   185 void CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL()
   180 TInt CMPXVideoPlaybackDisplayHandler::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd )
   186 {
   181 {
   187     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL()"));
   182     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()"));
   188 
   183 
   189     if ( iVideoHeight > 0 && iVideoWidth > 0 )
   184     TInt aspectRatio;
       
   185 
       
   186 #ifdef SYMBIAN_BUILD_GCE
       
   187     aspectRatio = SetNgaAspectRatioL( aCmd );
       
   188 #endif
       
   189 
       
   190     //
       
   191     //  Update the aspect ratio in the array
       
   192     //
       
   193     TInt count = iAspectRatioArray.Count();
       
   194 
       
   195     if ( count > 0 && count > iCurrentIndexForAspectRatio )
       
   196     {
       
   197         iAspectRatioArray[iCurrentIndexForAspectRatio].scalingType = (TMMFScalingType)aspectRatio;
       
   198     }
       
   199 
       
   200     return aspectRatio;
       
   201 }
       
   202 
       
   203 // -------------------------------------------------------------------------------------------------
       
   204 //   CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL
       
   205 // -------------------------------------------------------------------------------------------------
       
   206 //
       
   207 TInt CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL(
       
   208                                           CMPXVideoPlaybackViewFileDetails* aFileDetails )
       
   209 {
       
   210     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL()"));
       
   211 
       
   212     TRect displayRect = iContainer->Rect();
       
   213     TReal displayAspectRatio = (TReal32)displayRect.Width() / (TReal32)displayRect.Height();
       
   214 
       
   215     TInt newAspectRatio = EMMFNatural;
       
   216 
       
   217     if ( aFileDetails->iVideoHeight > 0 && aFileDetails->iVideoWidth > 0 )
       
   218     {
   190     {
   219         TMMFScalingType scalingType = EMMFNatural;
   191         TMMFScalingType scalingType = EMMFNatural;
   220 
   192 
   221         TReal32 videoAspectRatio = (TReal32)aFileDetails->iVideoWidth /
   193         TReal videoAspectRatio = CalculateVideoAspectRatio();
   222                                    (TReal32)aFileDetails->iVideoHeight;
   194 
       
   195         MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL() displayAR = %f videoAR = %f)"),
       
   196             iDisplayAspectRatio, videoAspectRatio );
   223 
   197 
   224         TInt cnt = iAspectRatioArray.Count();
   198         TInt cnt = iAspectRatioArray.Count();
   225         TInt i = 0;
   199         TInt i = 0;
   226 
   200 
   227         //
   201         //
   228         //  check whether dat file has the information about (videoRatio + screenRatio)
   202         //  check whether dat file has the information about (videoRatio + screenRatio)
   229         //
   203         //
   230         for ( ; i < cnt ; i++ )
   204         for ( ; i < cnt ; i++ )
   231         {
   205         {
   232             if ( iAspectRatioArray[i].videoRatio == videoAspectRatio &&
   206             if ( IsAspectRatioEqual( iAspectRatioArray[i].videoRatio, videoAspectRatio ) &&
   233                  iAspectRatioArray[i].screenRatio == displayAspectRatio &&
   207                  IsAspectRatioEqual( iAspectRatioArray[i].screenRatio, iDisplayAspectRatio ) &&
   234                  ( scalingType = iAspectRatioArray[i].scalingType ) > 0 )
   208                  ( scalingType = iAspectRatioArray[i].scalingType ) > 0 )
   235             {
   209             {
       
   210                 MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL() ratio found)"));
   236                 break;
   211                 break;
   237             }
   212             }
   238         }
   213         }
   239 
   214 
   240         //
   215         //
   241         //  if can't find out match aspect ratio in dat file,
   216         //  if can't find out match aspect ratio in dat file,
   242         //  choose the scaling type through the rule        
   217         //  choose the scaling type through the rule
   243         //      aspectRatioDiff =  videoAspectRatio - aDisplayAspectRatio
   218         //      aspectRatioDiff =  videoAspectRatio - aDisplayAspectRatio
   244         //      aspectRatioDiff ==  0        ==> natural
   219         //      aspectRatioDiff ==  0        ==> natural
   245         //      aspectRatioDiff > 0.1        ==> zoom
   220         //      aspectRatioDiff > 0.1        ==> zoom
   246         //      aspectRatioDiff < - 0.3      ==> natural
   221         //      aspectRatioDiff < - 0.3      ==> natural
   247         //      aspectRatioDiff >= - 0.3 and <= 0.1   ==> stretch
   222         //      aspectRatioDiff >= - 0.3 and <= 0.1   ==> stretch
   248 
       
   249         //
   223         //
   250         if ( i == cnt )
   224         if ( i == cnt )
   251         {
   225         {
   252             if ( videoAspectRatio - displayAspectRatio > 0.1 )
   226             if ( videoAspectRatio - iDisplayAspectRatio > 0.1 )
   253             {
   227             {
   254                 scalingType = EMMFZoom;
   228                 scalingType = EMMFZoom;
   255             }
   229             }
   256             else if ( ( videoAspectRatio != displayAspectRatio ) &&
   230             else if ( ( ! IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ) ) &&
   257                       ( videoAspectRatio - displayAspectRatio > (- 0.3) ) )
   231                       ( videoAspectRatio - iDisplayAspectRatio > (- 0.3) ) )
   258             {
   232             {
   259                 scalingType = EMMFStretch;
   233                 scalingType = EMMFStretch;
   260             }
   234             }
   261 
   235 
   262             TMPXAspectRatio ratio;
   236             TMPXAspectRatio ratio;
   263 
   237 
   264             ratio.videoRatio = videoAspectRatio;
   238             ratio.videoRatio = videoAspectRatio;
   265             ratio.screenRatio = displayAspectRatio;
   239             ratio.screenRatio = iDisplayAspectRatio;
   266             ratio.scalingType = scalingType;
   240             ratio.scalingType = scalingType;
   267 
   241 
   268             iAspectRatioArray.Append( ratio );
   242             iAspectRatioArray.Append( ratio );
   269         }
   243         }
   270 
   244 
   279         else if ( scalingType == EMMFStretch )
   253         else if ( scalingType == EMMFStretch )
   280         {
   254         {
   281             aspectRatioCmd = EPbCmdStretchAspectRatio;
   255             aspectRatioCmd = EPbCmdStretchAspectRatio;
   282         }
   256         }
   283 
   257 
   284         newAspectRatio = SetAspectRatioL( aspectRatioCmd );
   258         SetAspectRatioL( aspectRatioCmd );
   285     }
   259 
   286 
   260         //
   287     return newAspectRatio;
   261         //  If the screen aspect ratio and the video aspect ratio are not equal,
       
   262         //  signal the controls controller to create the aspect ratio icon
       
   263         //
       
   264         if ( ShowAspectRatioIcon() )
       
   265         {
       
   266             iContainer->HandleEventL( EMPXControlCmdCreateAspectRatioIcon );
       
   267         }
       
   268         else
       
   269         {
       
   270             iContainer->HandleEventL( EMPXControlCmdDeleteAspectRatioIcon );
       
   271         }
       
   272     }
   288 }
   273 }
   289 
   274 
   290 // -------------------------------------------------------------------------------------------------
   275 // -------------------------------------------------------------------------------------------------
   291 //   CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL
   276 //   CMPXVideoPlaybackDisplayHandler::SaveAspectRatioL
   292 // -------------------------------------------------------------------------------------------------
   277 // -------------------------------------------------------------------------------------------------
   377         in.Close();
   362         in.Close();
   378     }
   363     }
   379 
   364 
   380     CleanupStack::PopAndDestroy();
   365     CleanupStack::PopAndDestroy();
   381 }
   366 }
   382 
       
   383 #ifdef SYMBIAN_BUILD_GCE
       
   384 
   367 
   385 // -------------------------------------------------------------------------------------------------
   368 // -------------------------------------------------------------------------------------------------
   386 //   CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL()
   369 //   CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL()
   387 // -------------------------------------------------------------------------------------------------
   370 // -------------------------------------------------------------------------------------------------
   388 //
   371 //
   427     //
   410     //
   428     //  Check if surface was created before window was ready
   411     //  Check if surface was created before window was ready
   429     //
   412     //
   430     if ( iSurfaceCached && ! iContainer->IsRealOneBitmapTimerActive() )
   413     if ( iSurfaceCached && ! iContainer->IsRealOneBitmapTimerActive() )
   431     {
   414     {
   432         iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect );
   415         AttachNewSurfaceToWindowL();
   433 
       
   434         if ( iContainer )
       
   435         {
       
   436             iContainer->HandleCommandL( EMPXPbvSurfaceCreated );
       
   437         }
       
   438 
       
   439         iSurfaceCached = EFalse;
       
   440     }
   416     }
   441 }
   417 }
   442 
   418 
   443 // -------------------------------------------------------------------------------------------------
   419 // -------------------------------------------------------------------------------------------------
   444 //   CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL()
   420 //   CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL()
   455     //
   431     //
   456     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
   432     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
   457     iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
   433     iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
   458     iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
   434     iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
   459 
   435 
       
   436     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL iCropRect[(%d,%d),(%d,%d)] iAspectRatio = (%d,%d)"),
       
   437         iCropRect.iTl.iX, iCropRect.iTl.iY, iCropRect.iBr.iX, iCropRect.iBr.iY,
       
   438         iAspectRatio.iNumerator, iAspectRatio.iDenominator );
       
   439 
   460     //
   440     //
   461     //  Add the surface unless the video display hasn't been created or
   441     //  Add the surface unless the video display hasn't been created or
   462     //  the Real One bitmap is being shown.
   442     //  the Real One bitmap is being shown.
   463     //
   443     //
   464     if ( iVideoDisplay && ! iContainer->IsRealOneBitmapTimerActive() )
   444     if ( iVideoDisplay && ! iContainer->IsRealOneBitmapTimerActive() )
   469         if ( ! oldSurfaceId.IsNull() )
   449         if ( ! oldSurfaceId.IsNull() )
   470         {
   450         {
   471             iVideoDisplay->RemoveSurface();
   451             iVideoDisplay->RemoveSurface();
   472         }
   452         }
   473 
   453 
   474         //
   454         AttachNewSurfaceToWindowL();
   475         //  Add new surface
       
   476         //
       
   477         iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect );
       
   478 
       
   479         if ( iContainer )
       
   480         {
       
   481             iContainer->HandleCommandL( EMPXPbvSurfaceCreated );
       
   482         }
       
   483     }
   455     }
   484     else
   456     else
   485     {
   457     {
   486         //
   458         //
   487         //  Save the surface information to add it when the display is ready
   459         //  Save the surface information to add it when the display is ready
   495 // -------------------------------------------------------------------------------------------------
   467 // -------------------------------------------------------------------------------------------------
   496 //
   468 //
   497 void CMPXVideoPlaybackDisplayHandler::SurfaceChangedL( CMPXMessage* aMessage )
   469 void CMPXVideoPlaybackDisplayHandler::SurfaceChangedL( CMPXMessage* aMessage )
   498 {
   470 {
   499     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceChangedL()"));
   471     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceChangedL()"));
       
   472 
       
   473     TVideoAspectRatio oldAspectRatio = iAspectRatio;
   500 
   474 
   501     //
   475     //
   502     //  Extract the surface parameters from the message
   476     //  Extract the surface parameters from the message
   503     //
   477     //
   504     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
   478     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
   513     {
   487     {
   514         //
   488         //
   515         //  Add new surface
   489         //  Add new surface
   516         //
   490         //
   517         iVideoDisplay->SurfaceParametersChanged( iSurfaceId, iCropRect, iAspectRatio );
   491         iVideoDisplay->SurfaceParametersChanged( iSurfaceId, iCropRect, iAspectRatio );
   518 
       
   519         iVideoDisplay->RedrawWindows( iCropRect );
   492         iVideoDisplay->RedrawWindows( iCropRect );
   520     }
   493 
       
   494         //
       
   495         //  Update the Aspect Ratio if it changed on the surface
       
   496         //
       
   497         if ( oldAspectRatio != iAspectRatio )
       
   498         {
       
   499             CalculateAspectRatioL();
       
   500         }
       
   501     }
       
   502 }
       
   503 
       
   504 // -------------------------------------------------------------------------------------------------
       
   505 //   CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL()
       
   506 // -------------------------------------------------------------------------------------------------
       
   507 //
       
   508 void CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL()
       
   509 {
       
   510     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL()"));
       
   511 
       
   512     CMPXCommand* cmd = CMPXCommand::NewL();
       
   513     CleanupStack::PushL( cmd );
       
   514 
       
   515     cmd->SetTObjectValueL<TBool>( KMPXCommandGeneralDoSync, ETrue );
       
   516     cmd->SetTObjectValueL<TInt>( KMPXCommandGeneralId, KMPXMediaIdVideoPlayback );
       
   517     cmd->SetTObjectValueL<TMPXVideoPlaybackCommand>( KMPXMediaVideoPlaybackCommand,
       
   518                                                      EPbCmdSurfaceRemovedFromWindow );
       
   519     cmd->SetTObjectValueL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId, iSurfaceId );
       
   520 
       
   521     iPlaybackUtility->CommandL( *cmd );
       
   522     CleanupStack::PopAndDestroy( cmd );
   521 }
   523 }
   522 
   524 
   523 // -------------------------------------------------------------------------------------------------
   525 // -------------------------------------------------------------------------------------------------
   524 //   CMPXVideoPlaybackDisplayHandler::SurfaceRemoved()
   526 //   CMPXVideoPlaybackDisplayHandler::SurfaceRemoved()
   525 // -------------------------------------------------------------------------------------------------
   527 // -------------------------------------------------------------------------------------------------
   534         {
   536         {
   535             MPX_TRAPD( err, iContainer->HandleCommandL( EMPXPbvSurfaceRemoved ) );
   537             MPX_TRAPD( err, iContainer->HandleCommandL( EMPXPbvSurfaceRemoved ) );
   536         }
   538         }
   537 
   539 
   538         iVideoDisplay->RemoveSurface();
   540         iVideoDisplay->RemoveSurface();
       
   541 
       
   542         //
       
   543         // Signal the playback plugin to remove the surface from Helix
       
   544         //
       
   545         MPX_TRAPD( err2, RemoveSurfaceFromPlaybackPluginL() );
   539     }
   546     }
   540 
   547 
   541     iSurfaceId = TSurfaceId::CreateNullId();
   548     iSurfaceId = TSurfaceId::CreateNullId();
   542 }
   549 }
   543 
   550 
   544 // -------------------------------------------------------------------------------------------------
   551 // -------------------------------------------------------------------------------------------------
   545 //   CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL()
   552 //   CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()
   546 // -------------------------------------------------------------------------------------------------
   553 // -------------------------------------------------------------------------------------------------
   547 //
   554 //
   548 TInt CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL( TMPXVideoPlaybackCommand aCmd )
   555 void CMPXVideoPlaybackDisplayHandler::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd )
   549 {
   556 {
   550     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL()"));
   557     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()"),
       
   558                    _L("aCmd = %d"), aCmd);
   551 
   559 
   552     TInt aspectRatio = EMMFNatural;
   560     TInt aspectRatio = EMMFNatural;
   553 
   561 
   554     switch ( aCmd )
   562     switch ( aCmd )
   555     {
   563     {
   579                                       iHorizontalPosition,
   587                                       iHorizontalPosition,
   580                                       iVerticalPosition,
   588                                       iVerticalPosition,
   581                                       iCropRect );
   589                                       iCropRect );
   582     }
   590     }
   583 
   591 
   584     return aspectRatio;
   592     //
   585 }
   593     //  Update the controls controller with the new aspect ratio
   586 
   594     //
   587 #endif
   595     if ( iContainer )
       
   596     {
       
   597         iContainer->HandleEventL( EMPXControlCmdSetAspectRatio, aspectRatio );
       
   598     }
       
   599 
       
   600     //
       
   601     //  Update the aspect ratio in the array
       
   602     //
       
   603     TInt count = iAspectRatioArray.Count();
       
   604 
       
   605     if ( count > 0 && count > iCurrentIndexForAspectRatio )
       
   606     {
       
   607         iAspectRatioArray[iCurrentIndexForAspectRatio].scalingType = (TMMFScalingType)aspectRatio;
       
   608     }
       
   609 }
   588 
   610 
   589 // -------------------------------------------------------------------------------------------------
   611 // -------------------------------------------------------------------------------------------------
   590 //   CMPXVideoPlaybackDisplayHandler::DoHandleRealOneBitmapTimeoutL()
   612 //   CMPXVideoPlaybackDisplayHandler::DoHandleRealOneBitmapTimeoutL()
   591 // -------------------------------------------------------------------------------------------------
   613 // -------------------------------------------------------------------------------------------------
   592 //
   614 //
   597     //
   619     //
   598     //  Check if surface was created before window was ready
   620     //  Check if surface was created before window was ready
   599     //
   621     //
   600     if ( iSurfaceCached && iVideoDisplay )
   622     if ( iSurfaceCached && iVideoDisplay )
   601     {
   623     {
   602         iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect );
   624         AttachNewSurfaceToWindowL();
   603 
   625     }
   604         if ( iContainer )
   626 }
   605         {
   627 
   606             iContainer->HandleCommandL( EMPXPbvSurfaceCreated );
   628 // -------------------------------------------------------------------------------------------------
   607         }
   629 //   CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL()
   608 
   630 // -------------------------------------------------------------------------------------------------
   609         iSurfaceCached = EFalse;
   631 //
   610     }
   632 void CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL()
   611 }
   633 {
   612 
   634     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL()"));
       
   635 
       
   636     //
       
   637     //  Calculate the video aspect ratio and set the proper value on the video display
       
   638     //  before attaching the surface
       
   639     //
       
   640     CalculateAspectRatioL();
       
   641 
       
   642     iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect );
       
   643 
       
   644     if ( iContainer )
       
   645     {
       
   646         iContainer->HandleCommandL( EMPXPbvSurfaceCreated );
       
   647     }
       
   648 
       
   649     iSurfaceCached = EFalse;
       
   650 }
       
   651 
       
   652 // -------------------------------------------------------------------------------------------------
       
   653 //   CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon()
       
   654 // -------------------------------------------------------------------------------------------------
       
   655 //
       
   656 TBool CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon()
       
   657 {
       
   658     TBool showAspectRatio = ETrue;
       
   659 
       
   660     TReal videoAspectRatio = CalculateVideoAspectRatio();
       
   661 
       
   662     if ( IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ) )
       
   663     {
       
   664         showAspectRatio = EFalse;
       
   665     }
       
   666 
       
   667     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon(%d)"), showAspectRatio);
       
   668 
       
   669     return showAspectRatio;
       
   670 }
       
   671 
       
   672 // -------------------------------------------------------------------------------------------------
       
   673 //   CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual()
       
   674 // -------------------------------------------------------------------------------------------------
       
   675 //
       
   676 TBool CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual( TReal aRatio1, TReal aRatio2 )
       
   677 {
       
   678     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual() ar1 = %f ar2 = %f)"),
       
   679             aRatio1, aRatio2 );
       
   680 
       
   681     TBool valuesEqual = EFalse;
       
   682     TReal arDiff = aRatio1 - aRatio2;
       
   683 
       
   684     if ( arDiff < 0.00001 && arDiff > -0.00001 )
       
   685     {
       
   686         valuesEqual = ETrue;
       
   687     }
       
   688 
       
   689     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual(%d)"), valuesEqual);
       
   690 
       
   691     return valuesEqual;
       
   692 }
       
   693 
       
   694 // -------------------------------------------------------------------------------------------------
       
   695 //   CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio()
       
   696 // -------------------------------------------------------------------------------------------------
       
   697 //
       
   698 TReal CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio()
       
   699 {
       
   700     TReal videoAspectRatio = 0.0;
       
   701 
       
   702     if ( iVideoHeight > 0 && iVideoWidth > 0 )
       
   703     {
       
   704         videoAspectRatio = (TReal32)iVideoWidth / (TReal32)iVideoHeight;
       
   705 
       
   706         //
       
   707         //  If the pixel aspect ratio is valid, use it to modify the videoAspectRatio
       
   708         //
       
   709         if ( iAspectRatio.iDenominator )
       
   710         {
       
   711             MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio() iAspectRatio = (%d,%d)"),
       
   712                 iAspectRatio.iNumerator, iAspectRatio.iDenominator );
       
   713 
       
   714             TReal32 par = (TReal32)iAspectRatio.iNumerator / (TReal32)iAspectRatio.iDenominator;
       
   715 
       
   716             videoAspectRatio *= par;
       
   717         }
       
   718     }
       
   719 
       
   720     MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio(%f)"), videoAspectRatio );
       
   721 
       
   722     return videoAspectRatio;
       
   723 }
   613 
   724 
   614 // End of File
   725 // End of File