diff -r 2d690156cf8f -r 315810614048 videoplayback/videoplaybackviews/src/mpxvideoplaybackdisplayhandler.cpp --- a/videoplayback/videoplaybackviews/src/mpxvideoplaybackdisplayhandler.cpp Thu Jul 15 18:41:27 2010 +0300 +++ b/videoplayback/videoplaybackviews/src/mpxvideoplaybackdisplayhandler.cpp Thu Aug 19 09:57:17 2010 +0300 @@ -16,7 +16,7 @@ */ -// Version : %version: 15 % +// Version : %version: 17 % #include @@ -24,13 +24,13 @@ #include #include #include +#include #include "mpxvideoplaybackdisplayhandler.h" #include "mpxvideoregion.h" #include "mpxvideoplaybackviewfiledetails.h" #include "mpxvideoplaybackcontainer.h" #include "mpxcommonvideoplaybackview.hrh" -#include _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" ); @@ -41,14 +41,12 @@ CMPXVideoPlaybackContainer* aContainer) : iPlaybackUtility( aPlayUtil ) , iContainer( aContainer ) -#ifdef SYMBIAN_BUILD_GCE , iScaleWidth( 100.0f ) , iScaleHeight( 100.0f ) , iHorizontalPosition( EHorizontalAlignCenter ) , iVerticalPosition( EVerticalAlignCenter ) , iRotation( EVideoRotationNone ) , iAutoScale( EAutoScaleBestFit ) -#endif { } @@ -60,13 +58,11 @@ iAspectRatioArray.Close(); -#ifdef SYMBIAN_BUILD_GCE if ( iVideoDisplay ) { delete iVideoDisplay; iVideoDisplay = NULL; } -#endif iSurfaceId = TSurfaceId::CreateNullId(); } @@ -87,26 +83,42 @@ } // ------------------------------------------------------------------------------------------------- -// CMPXVideoPlaybackDisplayHandler::ConstructL() +// CMPXVideoPlaybackDisplayHandler::ConstructL() // ------------------------------------------------------------------------------------------------- // void CMPXVideoPlaybackDisplayHandler::ConstructL() { LoadAspectRatioL(); + + TRect displayRect = iContainer->Rect(); + iDisplayAspectRatio = (TReal32)displayRect.Width() / (TReal32)displayRect.Height(); + + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::ConstructL() iDisplayAspectRatio = %f"), + iDisplayAspectRatio ); } // ------------------------------------------------------------------------------------------------- // CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL() // ------------------------------------------------------------------------------------------------- // -void CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL( CWsScreenDevice& aScreenDevice, - RWindow& aWin ) +void CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL( + CWsScreenDevice& aScreenDevice, + RWindow& aWin, + CMPXVideoPlaybackViewFileDetails* aFileDetails ) { MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL()")); -#ifdef SYMBIAN_BUILD_GCE + // + // Save off the video aspect ratio + // + iVideoHeight = aFileDetails->iVideoHeight; + iVideoWidth = aFileDetails->iVideoWidth; + + MPX_DEBUG( + _L("CMPXVideoPlaybackDisplayHandler::CreateDisplayWindowL() clip size (%d,%d)"), + iVideoHeight, iVideoWidth ); + AddDisplayWindowL( aScreenDevice, aWin, &aWin ); -#endif } // ------------------------------------------------------------------------------------------------- @@ -117,7 +129,6 @@ { MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveDisplayWindow()")); -#ifdef SYMBIAN_BUILD_GCE if ( iVideoDisplay ) { // @@ -131,7 +142,6 @@ delete iVideoDisplay; iVideoDisplay = NULL; } -#endif iSurfaceId = TSurfaceId::CreateNullId(); } @@ -150,76 +160,40 @@ switch ( message ) { -#ifdef SYMBIAN_BUILD_GCE case EPbMsgVideoSurfaceCreated: { - MPX_DEBUG(_L(" message = EPbMsgVideoSurfaceCreated")); SurfaceCreatedL( aMessage ); break; } case EPbMsgVideoSurfaceChanged: { - MPX_DEBUG(_L(" message = EPbMsgVideoSurfaceChanged")); SurfaceChangedL( aMessage ); break; } case EPbMsgVideoSurfaceRemoved: { - MPX_DEBUG(_L(" message = EPbMsgVideoSurfaceRemoved")); SurfaceRemoved(); break; } -#endif } } // ------------------------------------------------------------------------------------------------- -// CMPXVideoPlaybackDisplayHandler::SetAspectRatioL() +// CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL // ------------------------------------------------------------------------------------------------- // -TInt CMPXVideoPlaybackDisplayHandler::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd ) +void CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL() { - MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()")); - - TInt aspectRatio; - -#ifdef SYMBIAN_BUILD_GCE - aspectRatio = SetNgaAspectRatioL( aCmd ); -#endif - - // - // Update the aspect ratio in the array - // - TInt count = iAspectRatioArray.Count(); + MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL()")); - if ( count > 0 && count > iCurrentIndexForAspectRatio ) - { - iAspectRatioArray[iCurrentIndexForAspectRatio].scalingType = (TMMFScalingType)aspectRatio; - } - - return aspectRatio; -} - -// ------------------------------------------------------------------------------------------------- -// CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL -// ------------------------------------------------------------------------------------------------- -// -TInt CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL( - CMPXVideoPlaybackViewFileDetails* aFileDetails ) -{ - MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetDefaultAspectRatioL()")); - - TRect displayRect = iContainer->Rect(); - TReal displayAspectRatio = (TReal32)displayRect.Width() / (TReal32)displayRect.Height(); - - TInt newAspectRatio = EMMFNatural; - - if ( aFileDetails->iVideoHeight > 0 && aFileDetails->iVideoWidth > 0 ) + if ( iVideoHeight > 0 && iVideoWidth > 0 ) { TMMFScalingType scalingType = EMMFNatural; - TReal32 videoAspectRatio = (TReal32)aFileDetails->iVideoWidth / - (TReal32)aFileDetails->iVideoHeight; + TReal videoAspectRatio = CalculateVideoAspectRatio(); + + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL() displayAR = %f videoAR = %f)"), + iDisplayAspectRatio, videoAspectRatio ); TInt cnt = iAspectRatioArray.Count(); TInt i = 0; @@ -229,32 +203,32 @@ // for ( ; i < cnt ; i++ ) { - if ( iAspectRatioArray[i].videoRatio == videoAspectRatio && - iAspectRatioArray[i].screenRatio == displayAspectRatio && + if ( IsAspectRatioEqual( iAspectRatioArray[i].videoRatio, videoAspectRatio ) && + IsAspectRatioEqual( iAspectRatioArray[i].screenRatio, iDisplayAspectRatio ) && ( scalingType = iAspectRatioArray[i].scalingType ) > 0 ) { + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateAspectRatioL() ratio found)")); break; } } // // if can't find out match aspect ratio in dat file, - // choose the scaling type through the rule + // choose the scaling type through the rule // aspectRatioDiff = videoAspectRatio - aDisplayAspectRatio // aspectRatioDiff == 0 ==> natural // aspectRatioDiff > 0.1 ==> zoom // aspectRatioDiff < - 0.3 ==> natural // aspectRatioDiff >= - 0.3 and <= 0.1 ==> stretch - // if ( i == cnt ) { - if ( videoAspectRatio - displayAspectRatio > 0.1 ) + if ( videoAspectRatio - iDisplayAspectRatio > 0.1 ) { scalingType = EMMFZoom; } - else if ( ( videoAspectRatio != displayAspectRatio ) && - ( videoAspectRatio - displayAspectRatio > (- 0.3) ) ) + else if ( ( ! IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ) ) && + ( videoAspectRatio - iDisplayAspectRatio > (- 0.3) ) ) { scalingType = EMMFStretch; } @@ -262,7 +236,7 @@ TMPXAspectRatio ratio; ratio.videoRatio = videoAspectRatio; - ratio.screenRatio = displayAspectRatio; + ratio.screenRatio = iDisplayAspectRatio; ratio.scalingType = scalingType; iAspectRatioArray.Append( ratio ); @@ -281,10 +255,21 @@ aspectRatioCmd = EPbCmdStretchAspectRatio; } - newAspectRatio = SetAspectRatioL( aspectRatioCmd ); + SetAspectRatioL( aspectRatioCmd ); + + // + // If the screen aspect ratio and the video aspect ratio are not equal, + // signal the controls controller to create the aspect ratio icon + // + if ( ShowAspectRatioIcon() ) + { + iContainer->HandleEventL( EMPXControlCmdCreateAspectRatioIcon ); + } + else + { + iContainer->HandleEventL( EMPXControlCmdDeleteAspectRatioIcon ); + } } - - return newAspectRatio; } // ------------------------------------------------------------------------------------------------- @@ -380,8 +365,6 @@ CleanupStack::PopAndDestroy(); } -#ifdef SYMBIAN_BUILD_GCE - // ------------------------------------------------------------------------------------------------- // CMPXVideoPlaybackDisplayHandler::AddDisplayWindowL() // ------------------------------------------------------------------------------------------------- @@ -429,14 +412,7 @@ // if ( iSurfaceCached && ! iContainer->IsRealOneBitmapTimerActive() ) { - iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect ); - - if ( iContainer ) - { - iContainer->HandleCommandL( EMPXPbvSurfaceCreated ); - } - - iSurfaceCached = EFalse; + AttachNewSurfaceToWindowL(); } } @@ -457,6 +433,10 @@ iCropRect = aMessage->ValueTObjectL( KMPXMediaVideoDisplayCropRect ); iAspectRatio = aMessage->ValueTObjectL( KMPXMediaVideoDisplayAspectRatio ); + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::SurfaceCreatedL iCropRect[(%d,%d),(%d,%d)] iAspectRatio = (%d,%d)"), + iCropRect.iTl.iX, iCropRect.iTl.iY, iCropRect.iBr.iX, iCropRect.iBr.iY, + iAspectRatio.iNumerator, iAspectRatio.iDenominator ); + // // Add the surface unless the video display hasn't been created or // the Real One bitmap is being shown. @@ -471,15 +451,7 @@ iVideoDisplay->RemoveSurface(); } - // - // Add new surface - // - iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect ); - - if ( iContainer ) - { - iContainer->HandleCommandL( EMPXPbvSurfaceCreated ); - } + AttachNewSurfaceToWindowL(); } else { @@ -498,6 +470,8 @@ { MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SurfaceChangedL()")); + TVideoAspectRatio oldAspectRatio = iAspectRatio; + // // Extract the surface parameters from the message // @@ -515,12 +489,40 @@ // Add new surface // iVideoDisplay->SurfaceParametersChanged( iSurfaceId, iCropRect, iAspectRatio ); + iVideoDisplay->RedrawWindows( iCropRect ); - iVideoDisplay->RedrawWindows( iCropRect ); + // + // Update the Aspect Ratio if it changed on the surface + // + if ( oldAspectRatio != iAspectRatio ) + { + CalculateAspectRatioL(); + } } } // ------------------------------------------------------------------------------------------------- +// CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL() +// ------------------------------------------------------------------------------------------------- +// +void CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL() +{ + MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::RemoveSurfaceFromPlaybackPluginL()")); + + CMPXCommand* cmd = CMPXCommand::NewL(); + CleanupStack::PushL( cmd ); + + cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue ); + cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXMediaIdVideoPlayback ); + cmd->SetTObjectValueL( KMPXMediaVideoPlaybackCommand, + EPbCmdSurfaceRemovedFromWindow ); + cmd->SetTObjectValueL( KMPXMediaVideoDisplayTSurfaceId, iSurfaceId ); + + iPlaybackUtility->CommandL( *cmd ); + CleanupStack::PopAndDestroy( cmd ); +} + +// ------------------------------------------------------------------------------------------------- // CMPXVideoPlaybackDisplayHandler::SurfaceRemoved() // ------------------------------------------------------------------------------------------------- // @@ -536,18 +538,24 @@ } iVideoDisplay->RemoveSurface(); + + // + // Signal the playback plugin to remove the surface from Helix + // + MPX_TRAPD( err2, RemoveSurfaceFromPlaybackPluginL() ); } iSurfaceId = TSurfaceId::CreateNullId(); } // ------------------------------------------------------------------------------------------------- -// CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL() +// CMPXVideoPlaybackDisplayHandler::SetAspectRatioL() // ------------------------------------------------------------------------------------------------- // -TInt CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL( TMPXVideoPlaybackCommand aCmd ) +void CMPXVideoPlaybackDisplayHandler::SetAspectRatioL( TMPXVideoPlaybackCommand aCmd ) { - MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetNgaAspectRatioL()")); + MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::SetAspectRatioL()"), + _L("aCmd = %d"), aCmd); TInt aspectRatio = EMMFNatural; @@ -581,11 +589,25 @@ iCropRect ); } - return aspectRatio; + // + // Update the controls controller with the new aspect ratio + // + if ( iContainer ) + { + iContainer->HandleEventL( EMPXControlCmdSetAspectRatio, aspectRatio ); + } + + // + // Update the aspect ratio in the array + // + TInt count = iAspectRatioArray.Count(); + + if ( count > 0 && count > iCurrentIndexForAspectRatio ) + { + iAspectRatioArray[iCurrentIndexForAspectRatio].scalingType = (TMMFScalingType)aspectRatio; + } } -#endif - // ------------------------------------------------------------------------------------------------- // CMPXVideoPlaybackDisplayHandler::DoHandleRealOneBitmapTimeoutL() // ------------------------------------------------------------------------------------------------- @@ -599,16 +621,105 @@ // if ( iSurfaceCached && iVideoDisplay ) { - iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect ); - - if ( iContainer ) - { - iContainer->HandleCommandL( EMPXPbvSurfaceCreated ); - } - - iSurfaceCached = EFalse; + AttachNewSurfaceToWindowL(); } } +// ------------------------------------------------------------------------------------------------- +// CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL() +// ------------------------------------------------------------------------------------------------- +// +void CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL() +{ + MPX_ENTER_EXIT(_L("CMPXVideoPlaybackDisplayHandler::AttachNewSurfaceToWindowL()")); + + // + // Calculate the video aspect ratio and set the proper value on the video display + // before attaching the surface + // + CalculateAspectRatioL(); + + iVideoDisplay->SurfaceCreated( iSurfaceId, iCropRect, iAspectRatio, iCropRect ); + + if ( iContainer ) + { + iContainer->HandleCommandL( EMPXPbvSurfaceCreated ); + } + + iSurfaceCached = EFalse; +} + +// ------------------------------------------------------------------------------------------------- +// CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon() +// ------------------------------------------------------------------------------------------------- +// +TBool CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon() +{ + TBool showAspectRatio = ETrue; + + TReal videoAspectRatio = CalculateVideoAspectRatio(); + + if ( IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ) ) + { + showAspectRatio = EFalse; + } + + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::ShowAspectRatioIcon(%d)"), showAspectRatio); + + return showAspectRatio; +} + +// ------------------------------------------------------------------------------------------------- +// CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual() +// ------------------------------------------------------------------------------------------------- +// +TBool CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual( TReal aRatio1, TReal aRatio2 ) +{ + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual() ar1 = %f ar2 = %f)"), + aRatio1, aRatio2 ); + + TBool valuesEqual = EFalse; + TReal arDiff = aRatio1 - aRatio2; + + if ( arDiff < 0.00001 && arDiff > -0.00001 ) + { + valuesEqual = ETrue; + } + + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::IsAspectRatioEqual(%d)"), valuesEqual); + + return valuesEqual; +} + +// ------------------------------------------------------------------------------------------------- +// CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio() +// ------------------------------------------------------------------------------------------------- +// +TReal CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio() +{ + TReal videoAspectRatio = 0.0; + + if ( iVideoHeight > 0 && iVideoWidth > 0 ) + { + videoAspectRatio = (TReal32)iVideoWidth / (TReal32)iVideoHeight; + + // + // If the pixel aspect ratio is valid, use it to modify the videoAspectRatio + // + if ( iAspectRatio.iDenominator ) + { + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio() iAspectRatio = (%d,%d)"), + iAspectRatio.iNumerator, iAspectRatio.iDenominator ); + + TReal32 par = (TReal32)iAspectRatio.iNumerator / (TReal32)iAspectRatio.iDenominator; + + videoAspectRatio *= par; + } + } + + MPX_DEBUG(_L("CMPXVideoPlaybackDisplayHandler::CalculateVideoAspectRatio(%f)"), videoAspectRatio ); + + return videoAspectRatio; +} // End of File