diff -r 4707a0db12f6 -r adb51f74b890 videoplayback/videoplaybackview/viewsrc/videoplaybackdisplayhandler.cpp --- a/videoplayback/videoplaybackview/viewsrc/videoplaybackdisplayhandler.cpp Mon Sep 20 18:25:37 2010 +0300 +++ b/videoplayback/videoplaybackview/viewsrc/videoplaybackdisplayhandler.cpp Tue Oct 05 09:26:49 2010 +0300 @@ -15,13 +15,12 @@ * */ -// Version : %version: 29 % +// Version : %version: 31 % #include #include #include #include -#include #include #include "videocontainer.h" @@ -36,10 +35,8 @@ _LIT( KAspectRatioFile, "c:\\private\\200159b2\\mpxvideoplayer_aspect_ratio.dat" ); -CVideoPlaybackDisplayHandler::CVideoPlaybackDisplayHandler( MMPXPlaybackUtility* aPlayUtil, - CMPXVideoViewWrapper* aViewWrapper ) - : iPlaybackUtility( aPlayUtil ) - , iTransitionEffectCnt( 0 ) +CVideoPlaybackDisplayHandler::CVideoPlaybackDisplayHandler( CMPXVideoViewWrapper* aViewWrapper ) + : iTransitionEffectCnt( 0 ) , iViewWrapper( aViewWrapper ) , iScaleWidth( 100.0f ) , iScaleHeight( 100.0f ) @@ -81,13 +78,12 @@ } CVideoPlaybackDisplayHandler* -CVideoPlaybackDisplayHandler::NewL( MMPXPlaybackUtility* aPlayUtil, - CMPXVideoViewWrapper* aViewWrapper ) +CVideoPlaybackDisplayHandler::NewL( CMPXVideoViewWrapper* aViewWrapper ) { MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::NewL()")); CVideoPlaybackDisplayHandler* self = - new(ELeave) CVideoPlaybackDisplayHandler( aPlayUtil, aViewWrapper ); + new(ELeave) CVideoPlaybackDisplayHandler( aViewWrapper ); CleanupStack::PushL( self ); self->ConstructL(); @@ -113,10 +109,22 @@ RWsSession& /*aWs*/, CWsScreenDevice& aScreenDevice, RWindow& aWin, - TRect aDisplayRect ) + TRect aDisplayRect, + VideoPlaybackViewFileDetails* aFileDetails ) { MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::CreateDisplayWindowL()")); + iFileDetails = aFileDetails; + + // + // get window aspect ratio + // if device is in landscape mode, width > height + // if device is in portrait mode, width < height + // + TReal32 width = (TReal32) aDisplayRect.Width(); + TReal32 height = (TReal32) aDisplayRect.Height(); + iDisplayAspectRatio = (width > height)? (width / height) : (height / width); + if ( ! iVideoContainer ) { iVideoContainer = new ( ELeave ) CVideoContainer(); @@ -125,6 +133,8 @@ } RWindowBase *videoWindow = iVideoContainer->DrawableWindow(); + ((RWindow*)videoWindow )->SetBackgroundColor( KRgbBlack ); + videoWindow->SetOrdinalPosition( -1 ); (&aWin)->SetOrdinalPosition( 0 ); @@ -219,22 +229,32 @@ } // ------------------------------------------------------------------------------------------------- -// CVideoPlaybackDisplayHandler::SetDefaultAspectRatioL +// CVideoPlaybackDisplayHandler::CalculateAspectRatioL // ------------------------------------------------------------------------------------------------- // -TInt CVideoPlaybackDisplayHandler::SetDefaultAspectRatioL( - VideoPlaybackViewFileDetails* aFileDetails, TReal32 aDisplayAspectRatio ) +TInt CVideoPlaybackDisplayHandler::CalculateAspectRatioL() { - MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::SetDefaultAspectRatioL()")); + MPX_ENTER_EXIT(_L("CVideoPlaybackDisplayHandler::CalculateAspectRatioL()")); TInt newAspectRatio = EMMFNatural; - if ( aFileDetails->mVideoHeight > 0 && aFileDetails->mVideoWidth > 0 ) + if ( iFileDetails->mVideoHeight > 0 && iFileDetails->mVideoWidth > 0 ) { TMMFScalingType scalingType = EMMFNatural; - TReal32 videoAspectRatio = (TReal32)aFileDetails->mVideoWidth / - (TReal32)aFileDetails->mVideoHeight; + TReal32 videoAspectRatio = (TReal32)iFileDetails->mVideoWidth / + (TReal32)iFileDetails->mVideoHeight; + // + // If the pixel aspect ratio is valid, use it to modify the videoAspectRatio + // + if ( iAspectRatio.iDenominator ) + { + MPX_DEBUG(_L("VideoPlaybackDisplayHandler::CalculateAspectRatioL() iAspectRatio = (%d,%d)"), + iAspectRatio.iNumerator, iAspectRatio.iDenominator ); + + TReal32 par = (TReal32)iAspectRatio.iNumerator / (TReal32)iAspectRatio.iDenominator; + videoAspectRatio *= par; + } TInt cnt = iAspectRatioArray.Count(); TInt i = 0; @@ -244,8 +264,8 @@ // for ( ; i < cnt ; i++ ) { - if ( iAspectRatioArray[i].videoRatio == videoAspectRatio && - iAspectRatioArray[i].screenRatio == aDisplayAspectRatio && + if ( IsAspectRatioEqual( iAspectRatioArray[i].videoRatio, videoAspectRatio ) && + IsAspectRatioEqual( iAspectRatioArray[i].screenRatio, iDisplayAspectRatio ) && ( scalingType = iAspectRatioArray[i].scalingType ) > 0 ) { break; @@ -255,21 +275,33 @@ // // if can't find out match aspect ratio in dat file, // 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 + // aspectRatioDiff = videoAspectRatio - iDisplayAspectRatio + // aspectRatioDiff >= - 0.00001 and <= 0.00001 ==> natural + // aspectRatioDiff > 0.1 ==> zoom + // aspectRatioDiff < - 0.3 ==> natural + // aspectRatioDiff >= - 0.3 and <= 0.1 ==> stretch + // + // -0.3 -0.00001 0.00001 0.1 + // ------------------------------------------------------------ + // Natural | Stretch | Natural | Stretch | Zoom // if ( i == cnt ) { - if ( videoAspectRatio - aDisplayAspectRatio > 0.1 ) + TReal32 aspectRatioDiff = videoAspectRatio - iDisplayAspectRatio; + + MPX_DEBUG(_L("VideoPlaybackDisplayHandler::CalculateAspectRatioL() videoAspectRatio = d,iDisplayAspectRatio = %d)"), + videoAspectRatio, iDisplayAspectRatio ); + + if ( IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ) ) + { + scalingType = EMMFNatural; + } + else if ( aspectRatioDiff > 0.1 ) { scalingType = EMMFZoom; } - else if ( ( videoAspectRatio != aDisplayAspectRatio ) && - ( videoAspectRatio - aDisplayAspectRatio > (- 0.3) ) ) + else if ( aspectRatioDiff > - 0.3 ) { scalingType = EMMFStretch; } @@ -277,12 +309,15 @@ TMPXAspectRatio ratio; ratio.videoRatio = videoAspectRatio; - ratio.screenRatio = aDisplayAspectRatio; + ratio.screenRatio = iDisplayAspectRatio; ratio.scalingType = scalingType; iAspectRatioArray.Append( ratio ); } + iFileDetails->mAspectRatioChangeable = + ! IsAspectRatioEqual( videoAspectRatio, iDisplayAspectRatio ); + iCurrentIndexForAspectRatio = i; TMPXVideoPlaybackCommand aspectRatioCmd = EPbCmdNaturalAspectRatio; @@ -485,7 +520,38 @@ if ( iVideoDisplay ) { - iVideoDisplay->SetVideoExtentL( *iWindowBase, aRect, TRect( iWindowBase->Size() ) ); + TRect temp = aRect; + + MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::SetVideoRectL() origianl rect %d %d %d %d"), + temp.iTl.iX, temp.iTl.iY, temp.iBr.iX, temp.iBr.iY ); + + // + // Need to transform based on rotation clockwise + // since the input rect is based on orbit orientation(which can be landscape or potrait) + // and the video surface is always in device orientation(can't be changed by anything). + // If iRotation is EVideoRotationNone, + // we don't need to transfrom the rect since video and ui surfaces are in same orietation. + // but if iRotation is not EVideoRotationNone, + // we need to transform the rect based on clockwise. + // + switch( iRotation ) + { + case EVideoRotationClockwise90: + { + int screenWidth = iWindowBase->Size().iWidth; + + temp = TRect( screenWidth - aRect.iBr.iY, + aRect.iTl.iX, + screenWidth - aRect.iTl.iY, + aRect.iBr.iX ); + break; + } + } + + MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::SetVideoRectL() transformed rect %d %d %d %d"), + temp.iTl.iX, temp.iTl.iY, temp.iBr.iX, temp.iBr.iY ); + + iVideoDisplay->SetVideoExtentL( *iWindowBase, temp, iCropRect ); } } @@ -541,6 +607,7 @@ ); MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::AddDisplayWindowL() Display Added")); + // // Check if surface was created before window was ready // @@ -574,6 +641,8 @@ iCropRect = aMessage->ValueTObjectL( KMPXMediaVideoDisplayCropRect ); iAspectRatio = aMessage->ValueTObjectL( KMPXMediaVideoDisplayAspectRatio ); + iViewWrapper->SetDefaultAspectRatio( CalculateAspectRatioL() ); + if ( iVideoDisplay ) { // @@ -619,6 +688,8 @@ iCropRect = aMessage->ValueTObjectL( KMPXMediaVideoDisplayCropRect ); iAspectRatio = aMessage->ValueTObjectL( KMPXMediaVideoDisplayAspectRatio ); + iViewWrapper->SetDefaultAspectRatio( CalculateAspectRatioL() ); + if ( iVideoDisplay ) { // @@ -694,4 +765,26 @@ return aspectRatio; } +// ------------------------------------------------------------------------------------------------- +// CVideoPlaybackDisplayHandler::IsAspectRatioEqual() +// ------------------------------------------------------------------------------------------------- +// +TBool CVideoPlaybackDisplayHandler::IsAspectRatioEqual( TReal32 aRatio1, TReal32 aRatio2 ) +{ + MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::IsAspectRatioEqual() ar1 = %f ar2 = %f)"), + aRatio1, aRatio2 ); + + TBool valuesEqual = EFalse; + TReal32 arDiff = aRatio1 - aRatio2; + + if ( arDiff < 0.00001 && arDiff > -0.00001 ) + { + valuesEqual = ETrue; + } + + MPX_DEBUG(_L("CVideoPlaybackDisplayHandler::IsAspectRatioEqual(%d)"), valuesEqual); + + return valuesEqual; +} + // End of File