videoplayback/videoplaybackview/viewsrc/videoplaybackdisplayhandler.cpp
changeset 66 adb51f74b890
parent 55 4bfa887905cf
child 67 72c709219fcd
equal deleted inserted replaced
63:4707a0db12f6 66:adb51f74b890
    13 *
    13 *
    14 * Description:   Implementation of video playback display handler
    14 * Description:   Implementation of video playback display handler
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // Version : %version:  29 %
    18 // Version : %version:  31 %
    19 
    19 
    20 #include <sysutil.h>
    20 #include <sysutil.h>
    21 #include <s32file.h>
    21 #include <s32file.h>
    22 #include <mpxcommand.h>
    22 #include <mpxcommand.h>
    23 #include <mpxcommandgeneraldefs.h>
    23 #include <mpxcommandgeneraldefs.h>
    24 #include <mpxplaybackutility.h>
       
    25 #include <mpxvideoplaybackdefs.h>
    24 #include <mpxvideoplaybackdefs.h>
    26 
    25 
    27 #include "videocontainer.h"
    26 #include "videocontainer.h"
    28 #include "mpxvideoviewwrapper.h"
    27 #include "mpxvideoviewwrapper.h"
    29 #include "videoplaybackdisplayhandler.h"
    28 #include "videoplaybackdisplayhandler.h"
    34 const TReal32 KTRANSITIONEFFECTCNT = 8;
    33 const TReal32 KTRANSITIONEFFECTCNT = 8;
    35 
    34 
    36 _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" );
    35 _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" );
    37 
    36 
    38 
    37 
    39 CVideoPlaybackDisplayHandler::CVideoPlaybackDisplayHandler( MMPXPlaybackUtility* aPlayUtil,
    38 CVideoPlaybackDisplayHandler::CVideoPlaybackDisplayHandler( CMPXVideoViewWrapper* aViewWrapper )
    40                                                             CMPXVideoViewWrapper* aViewWrapper )
    39     : iTransitionEffectCnt( 0 )
    41     : iPlaybackUtility( aPlayUtil )
       
    42     , iTransitionEffectCnt( 0 )
       
    43     , iViewWrapper( aViewWrapper )
    40     , iViewWrapper( aViewWrapper )
    44     , iScaleWidth( 100.0f )
    41     , iScaleWidth( 100.0f )
    45     , iScaleHeight( 100.0f )
    42     , iScaleHeight( 100.0f )
    46     , iHorizontalPosition( EHorizontalAlignCenter )
    43     , iHorizontalPosition( EHorizontalAlignCenter )
    47     , iVerticalPosition( EVerticalAlignCenter )
    44     , iVerticalPosition( EVerticalAlignCenter )
    79         iVideoContainer = NULL;
    76         iVideoContainer = NULL;
    80     }
    77     }
    81 }
    78 }
    82 
    79 
    83 CVideoPlaybackDisplayHandler*
    80 CVideoPlaybackDisplayHandler*
    84 CVideoPlaybackDisplayHandler::NewL( MMPXPlaybackUtility* aPlayUtil,
    81 CVideoPlaybackDisplayHandler::NewL( CMPXVideoViewWrapper* aViewWrapper )
    85                                     CMPXVideoViewWrapper* aViewWrapper )
       
    86 {
    82 {
    87     MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::NewL()"));
    83     MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::NewL()"));
    88 
    84 
    89     CVideoPlaybackDisplayHandler* self =
    85     CVideoPlaybackDisplayHandler* self =
    90         new(ELeave) CVideoPlaybackDisplayHandler( aPlayUtil, aViewWrapper );
    86         new(ELeave) CVideoPlaybackDisplayHandler( aViewWrapper );
    91 
    87 
    92     CleanupStack::PushL( self );
    88     CleanupStack::PushL( self );
    93     self->ConstructL();
    89     self->ConstructL();
    94     CleanupStack::Pop();
    90     CleanupStack::Pop();
    95     return self;
    91     return self;
   111 //
   107 //
   112 void CVideoPlaybackDisplayHandler::CreateDisplayWindowL(
   108 void CVideoPlaybackDisplayHandler::CreateDisplayWindowL(
   113                                           RWsSession& /*aWs*/,
   109                                           RWsSession& /*aWs*/,
   114                                           CWsScreenDevice& aScreenDevice,
   110                                           CWsScreenDevice& aScreenDevice,
   115                                           RWindow& aWin,
   111                                           RWindow& aWin,
   116                                           TRect aDisplayRect )
   112                                           TRect aDisplayRect,
       
   113                                           VideoPlaybackViewFileDetails* aFileDetails )
   117 {
   114 {
   118     MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::CreateDisplayWindowL()"));
   115     MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::CreateDisplayWindowL()"));
       
   116 
       
   117     iFileDetails = aFileDetails;
       
   118 
       
   119     //
       
   120     // get window aspect ratio
       
   121     //   if device is in landscape mode, width > height
       
   122     //   if device is in portrait mode, width < height
       
   123     //
       
   124     TReal32 width = (TReal32) aDisplayRect.Width();
       
   125     TReal32 height = (TReal32) aDisplayRect.Height();
       
   126     iDisplayAspectRatio = (width > height)? (width / height) : (height / width);
   119 
   127 
   120     if ( ! iVideoContainer )
   128     if ( ! iVideoContainer )
   121     {
   129     {
   122         iVideoContainer = new ( ELeave ) CVideoContainer();
   130         iVideoContainer = new ( ELeave ) CVideoContainer();
   123         iVideoContainer->ConstructL();
   131         iVideoContainer->ConstructL();
   124         iVideoContainer->SetRect( aDisplayRect );
   132         iVideoContainer->SetRect( aDisplayRect );
   125     }
   133     }
   126 
   134 
   127     RWindowBase *videoWindow = iVideoContainer->DrawableWindow();
   135     RWindowBase *videoWindow = iVideoContainer->DrawableWindow();
       
   136     ((RWindow*)videoWindow )->SetBackgroundColor( KRgbBlack );
       
   137 
   128     videoWindow->SetOrdinalPosition( -1 );
   138     videoWindow->SetOrdinalPosition( -1 );
   129     (&aWin)->SetOrdinalPosition( 0 );
   139     (&aWin)->SetOrdinalPosition( 0 );
   130 
   140 
   131     MPX_DEBUG(_L("VideoWindow ordinal position is: %d"), videoWindow->OrdinalPosition());
   141     MPX_DEBUG(_L("VideoWindow ordinal position is: %d"), videoWindow->OrdinalPosition());
   132     MPX_DEBUG(_L("UiWindow ordinal position is: %d"), (&aWin)->OrdinalPosition());
   142     MPX_DEBUG(_L("UiWindow ordinal position is: %d"), (&aWin)->OrdinalPosition());
   217 
   227 
   218     return aspectRatio;
   228     return aspectRatio;
   219 }
   229 }
   220 
   230 
   221 // -------------------------------------------------------------------------------------------------
   231 // -------------------------------------------------------------------------------------------------
   222 //   CVideoPlaybackDisplayHandler::SetDefaultAspectRatioL
   232 //   CVideoPlaybackDisplayHandler::CalculateAspectRatioL
   223 // -------------------------------------------------------------------------------------------------
   233 // -------------------------------------------------------------------------------------------------
   224 //
   234 //
   225 TInt CVideoPlaybackDisplayHandler::SetDefaultAspectRatioL(
   235 TInt CVideoPlaybackDisplayHandler::CalculateAspectRatioL()
   226         VideoPlaybackViewFileDetails* aFileDetails, TReal32 aDisplayAspectRatio )
   236 {
   227 {
   237     MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::CalculateAspectRatioL()"));
   228     MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SetDefaultAspectRatioL()"));
       
   229 
   238 
   230     TInt newAspectRatio = EMMFNatural;
   239     TInt newAspectRatio = EMMFNatural;
   231 
   240 
   232     if ( aFileDetails->mVideoHeight > 0 && aFileDetails->mVideoWidth > 0 )
   241     if ( iFileDetails->mVideoHeight > 0 && iFileDetails->mVideoWidth > 0 )
   233     {
   242     {
   234         TMMFScalingType scalingType = EMMFNatural;
   243         TMMFScalingType scalingType = EMMFNatural;
   235 
   244 
   236         TReal32 videoAspectRatio = (TReal32)aFileDetails->mVideoWidth /
   245         TReal32 videoAspectRatio = (TReal32)iFileDetails->mVideoWidth /
   237                                    (TReal32)aFileDetails->mVideoHeight;
   246                                    (TReal32)iFileDetails->mVideoHeight;
       
   247         //
       
   248         //  If the pixel aspect ratio is valid, use it to modify the videoAspectRatio
       
   249         //
       
   250         if ( iAspectRatio.iDenominator )
       
   251         {
       
   252             MPX_DEBUG(_L("VideoPlaybackDisplayHandler::CalculateAspectRatioL() iAspectRatio = (%d,%d)"),
       
   253                 iAspectRatio.iNumerator, iAspectRatio.iDenominator );
       
   254 
       
   255             TReal32 par = (TReal32)iAspectRatio.iNumerator / (TReal32)iAspectRatio.iDenominator;
       
   256             videoAspectRatio *= par;
       
   257        }
   238 
   258 
   239         TInt cnt = iAspectRatioArray.Count();
   259         TInt cnt = iAspectRatioArray.Count();
   240         TInt i = 0;
   260         TInt i = 0;
   241 
   261 
   242         //
   262         //
   243         //  check whether dat file has the information about (videoRatio + screenRatio)
   263         //  check whether dat file has the information about (videoRatio + screenRatio)
   244         //
   264         //
   245         for ( ; i < cnt ; i++ )
   265         for ( ; i < cnt ; i++ )
   246         {
   266         {
   247             if ( iAspectRatioArray[i].videoRatio == videoAspectRatio &&
   267             if ( IsAspectRatioEqual( iAspectRatioArray[i].videoRatio, videoAspectRatio ) &&
   248                  iAspectRatioArray[i].screenRatio == aDisplayAspectRatio &&
   268                  IsAspectRatioEqual( iAspectRatioArray[i].screenRatio, iDisplayAspectRatio ) &&
   249                  ( scalingType = iAspectRatioArray[i].scalingType ) > 0 )
   269                  ( scalingType = iAspectRatioArray[i].scalingType ) > 0 )
   250             {
   270             {
   251                 break;
   271                 break;
   252             }
   272             }
   253         }
   273         }
   254 
   274 
   255         //
   275         //
   256         //  if can't find out match aspect ratio in dat file,
   276         //  if can't find out match aspect ratio in dat file,
   257         //  choose the scaling type through the rule
   277         //  choose the scaling type through the rule
   258         //      aspectRatioDiff =  videoAspectRatio - aDisplayAspectRatio
   278         //      aspectRatioDiff =  videoAspectRatio - iDisplayAspectRatio
   259         //      aspectRatioDiff ==  0        ==> natural
   279         //      aspectRatioDiff >= - 0.00001 and <= 0.00001    ==> natural
   260         //      aspectRatioDiff > 0.1        ==> zoom
   280         //      aspectRatioDiff > 0.1                          ==> zoom
   261         //      aspectRatioDiff < - 0.3      ==> natural
   281         //      aspectRatioDiff < - 0.3                        ==> natural
   262         //      aspectRatioDiff >= - 0.3 and <= 0.1   ==> stretch
   282         //      aspectRatioDiff >= - 0.3 and <= 0.1            ==> stretch
       
   283         //
       
   284         //               -0.3      -0.00001       0.00001         0.1
       
   285         //     ------------------------------------------------------------
       
   286         //         Natural |   Stretch  |   Natural  |   Stretch   |  Zoom
   263         //
   287         //
   264 
   288 
   265         if ( i == cnt )
   289         if ( i == cnt )
   266         {
   290         {
   267             if ( videoAspectRatio - aDisplayAspectRatio > 0.1 )
   291             TReal32 aspectRatioDiff = videoAspectRatio - iDisplayAspectRatio;
       
   292 
       
   293             MPX_DEBUG(_L("VideoPlaybackDisplayHandler::CalculateAspectRatioL() videoAspectRatio = d,iDisplayAspectRatio = %d)"),
       
   294                     videoAspectRatio, iDisplayAspectRatio );
       
   295 
       
   296             if ( IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio )  )
       
   297             {
       
   298                 scalingType = EMMFNatural;
       
   299             }
       
   300             else if ( aspectRatioDiff > 0.1 )
   268             {
   301             {
   269                 scalingType = EMMFZoom;
   302                 scalingType = EMMFZoom;
   270             }
   303             }
   271             else if ( ( videoAspectRatio != aDisplayAspectRatio ) &&
   304             else if ( aspectRatioDiff > - 0.3 )
   272                       ( videoAspectRatio - aDisplayAspectRatio > (- 0.3) ) )
       
   273             {
   305             {
   274                 scalingType = EMMFStretch;
   306                 scalingType = EMMFStretch;
   275             }
   307             }
   276 
   308 
   277             TMPXAspectRatio ratio;
   309             TMPXAspectRatio ratio;
   278 
   310 
   279             ratio.videoRatio = videoAspectRatio;
   311             ratio.videoRatio = videoAspectRatio;
   280             ratio.screenRatio = aDisplayAspectRatio;
   312             ratio.screenRatio = iDisplayAspectRatio;
   281             ratio.scalingType = scalingType;
   313             ratio.scalingType = scalingType;
   282 
   314 
   283             iAspectRatioArray.Append( ratio );
   315             iAspectRatioArray.Append( ratio );
   284         }
   316         }
       
   317 
       
   318         iFileDetails->mAspectRatioChangeable =
       
   319                 ! IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio );
   285 
   320 
   286         iCurrentIndexForAspectRatio = i;
   321         iCurrentIndexForAspectRatio = i;
   287 
   322 
   288         TMPXVideoPlaybackCommand aspectRatioCmd = EPbCmdNaturalAspectRatio;
   323         TMPXVideoPlaybackCommand aspectRatioCmd = EPbCmdNaturalAspectRatio;
   289 
   324 
   483 {
   518 {
   484     MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SetVideoRectL()"));
   519     MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SetVideoRectL()"));
   485 
   520 
   486     if ( iVideoDisplay )
   521     if ( iVideoDisplay )
   487     {
   522     {
   488         iVideoDisplay->SetVideoExtentL( *iWindowBase, aRect, TRect( iWindowBase->Size() ) );
   523         TRect temp = aRect;
       
   524 
       
   525         MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::SetVideoRectL() origianl rect %d %d %d %d"),
       
   526                 temp.iTl.iX, temp.iTl.iY, temp.iBr.iX, temp.iBr.iY );
       
   527 
       
   528         //
       
   529         // Need to transform based on rotation clockwise
       
   530         // since the input rect is based on orbit orientation(which can be landscape or potrait)
       
   531         // and the video surface is always in device orientation(can't be changed by anything).
       
   532         // If iRotation is EVideoRotationNone,
       
   533         // we don't need to transfrom the rect since video and ui surfaces are in same orietation.
       
   534         // but if iRotation is not EVideoRotationNone,
       
   535         // we need to transform the rect based on clockwise.
       
   536         //
       
   537         switch( iRotation )
       
   538         {
       
   539             case EVideoRotationClockwise90:
       
   540             {
       
   541                 int screenWidth = iWindowBase->Size().iWidth;
       
   542 
       
   543                 temp = TRect( screenWidth - aRect.iBr.iY,
       
   544                               aRect.iTl.iX,
       
   545                               screenWidth - aRect.iTl.iY,
       
   546                               aRect.iBr.iX );
       
   547                 break;
       
   548             }
       
   549         }
       
   550 
       
   551         MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::SetVideoRectL() transformed rect %d %d %d %d"),
       
   552                 temp.iTl.iX, temp.iTl.iY, temp.iBr.iX, temp.iBr.iY );
       
   553 
       
   554         iVideoDisplay->SetVideoExtentL( *iWindowBase, temp, iCropRect );
   489     }
   555     }
   490 }
   556 }
   491 
   557 
   492 // -------------------------------------------------------------------------------------------------
   558 // -------------------------------------------------------------------------------------------------
   493 //   CVideoPlaybackDisplayHandler::AddDisplayWindowL()
   559 //   CVideoPlaybackDisplayHandler::AddDisplayWindowL()
   539                                       iVerticalPosition,
   605                                       iVerticalPosition,
   540                                       aWin );
   606                                       aWin );
   541     );
   607     );
   542 
   608 
   543     MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::AddDisplayWindowL() Display Added"));
   609     MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::AddDisplayWindowL() Display Added"));
       
   610 
   544     //
   611     //
   545     //  Check if surface was created before window was ready
   612     //  Check if surface was created before window was ready
   546     //
   613     //
   547     if ( iSurfaceCached )
   614     if ( iSurfaceCached )
   548     {
   615     {
   572     //
   639     //
   573     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
   640     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
   574     iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
   641     iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
   575     iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
   642     iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
   576 
   643 
       
   644     iViewWrapper->SetDefaultAspectRatio( CalculateAspectRatioL() );
       
   645 
   577     if ( iVideoDisplay )
   646     if ( iVideoDisplay )
   578     {
   647     {
   579         //
   648         //
   580         //  Remove old surface if one exists
   649         //  Remove old surface if one exists
   581         //
   650         //
   616     //  Extract the surface parameters from the message
   685     //  Extract the surface parameters from the message
   617     //
   686     //
   618     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
   687     iSurfaceId = aMessage->ValueTObjectL<TSurfaceId>( KMPXMediaVideoDisplayTSurfaceId );
   619     iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
   688     iCropRect = aMessage->ValueTObjectL<TRect>( KMPXMediaVideoDisplayCropRect );
   620     iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
   689     iAspectRatio = aMessage->ValueTObjectL<TVideoAspectRatio>( KMPXMediaVideoDisplayAspectRatio );
       
   690 
       
   691     iViewWrapper->SetDefaultAspectRatio( CalculateAspectRatioL() );
   621 
   692 
   622     if ( iVideoDisplay )
   693     if ( iVideoDisplay )
   623     {
   694     {
   624         //
   695         //
   625         //  Add new surface
   696         //  Add new surface
   692     }
   763     }
   693 
   764 
   694     return aspectRatio;
   765     return aspectRatio;
   695 }
   766 }
   696 
   767 
       
   768 // -------------------------------------------------------------------------------------------------
       
   769 //   CVideoPlaybackDisplayHandler::IsAspectRatioEqual()
       
   770 // -------------------------------------------------------------------------------------------------
       
   771 //
       
   772 TBool CVideoPlaybackDisplayHandler::IsAspectRatioEqual( TReal32 aRatio1, TReal32 aRatio2 )
       
   773 {
       
   774     MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::IsAspectRatioEqual() ar1 = %f ar2 = %f)"),
       
   775             aRatio1, aRatio2 );
       
   776 
       
   777     TBool valuesEqual = EFalse;
       
   778     TReal32 arDiff = aRatio1 - aRatio2;
       
   779 
       
   780     if ( arDiff < 0.00001 && arDiff > -0.00001 )
       
   781     {
       
   782         valuesEqual = ETrue;
       
   783     }
       
   784 
       
   785     MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::IsAspectRatioEqual(%d)"), valuesEqual);
       
   786 
       
   787     return valuesEqual;
       
   788 }
       
   789 
   697 // End of File
   790 // End of File