mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp
branchRCL_3
changeset 19 8184f75a63d4
parent 12 b74061f7f3d2
child 23 545d349d14da
equal deleted inserted replaced
14:cd271b19d824 19:8184f75a63d4
    18 #include "mediaclientpolicyserverclient.h"
    18 #include "mediaclientpolicyserverclient.h"
    19 #include <surfaceeventhandler.h>
    19 #include <surfaceeventhandler.h>
    20 #include <mmf/plugin/mmfmediaclientextdisplayinterface.hrh>
    20 #include <mmf/plugin/mmfmediaclientextdisplayinterface.hrh>
    21 #include <e32cmn.h>
    21 #include <e32cmn.h>
    22 #include <ecom/ecom.h>
    22 #include <ecom/ecom.h>
       
    23 #include <centralrepository.h>
       
    24 
       
    25 const TUid KCRUidTvoutSettings = {0x1020730B};
       
    26 const TUint32 KSettingsTvAspectRatio = 0x00000001;
    23 
    27 
    24 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, TBool aExtDisplaySwitchingControl)
    28 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, TBool aExtDisplaySwitchingControl)
    25 	{
    29 	{
    26 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
    30 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
    27     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
    31     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
   832         }
   836         }
   833 
   837 
   834     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport1 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
   838     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport1 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
   835 
   839 
   836     TRect videoExtent(aWindowData.iVideoExtent);
   840     TRect videoExtent(aWindowData.iVideoExtent);
   837     
   841 
   838     TReal32 inputWidth = 0.0f;
   842     TReal32 inputWidth = 0.0f;
   839     TReal32 inputHeight = 0.0f;
   843     TReal32 inputHeight = 0.0f;
   840     TReal32 pixelAspectRatio = 0.0f;
   844     TReal32 pixelAspectRatio = 0.0f;
   841     switch (aWindowData.iRotation)
   845     switch (aWindowData.iRotation)
   842         {
   846         {
   897             deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
   901             deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
   898             }
   902             }
   899         }
   903         }
   900     else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
   904     else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
   901         {
   905         {
   902         // Don't do anything: the extent is already set to the size of the video extent.
   906         if(iSwitchedToExternalDisplay)
       
   907             {
       
   908             UpdateDeltaForExtDisplay(viewportAspect, videoExtent, deltaHeight, deltaWidth);
       
   909             }
   903         }
   910         }
   904     else if (aWindowData.iAutoScaleType == EAutoScaleNone)
   911     else if (aWindowData.iAutoScaleType == EAutoScaleNone)
   905         {
   912         {
   906         // for non-square pixels, reduce one dimension
   913         // for non-square pixels, reduce one dimension
   907         // TBD other option is to enlarge in the other dimension
   914         // TBD other option is to enlarge in the other dimension
  1182         }
  1189         }
  1183     
  1190     
  1184     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
  1191     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
  1185     }
  1192     }
  1186 
  1193 
  1187 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TBool aExtDisplayConnected)
  1194 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TExtDisplayConnectionProviderConnType aExtDisplayConnType)
  1188 	{
  1195 	{
  1189 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d", aExtDisplayConnected);
  1196 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnType=%d", aExtDisplayConnType);
  1190 	
  1197 	
  1191 	if(iExtDisplayConnected != aExtDisplayConnected)
  1198 	if(aExtDisplayConnType != iExtDisplayConnType)
  1192 	    {
  1199 	    {
  1193 	    iExtDisplayConnected = aExtDisplayConnected;
  1200         TExtDisplayConnectionProviderConnType prevExtDisplayConnType = iExtDisplayConnType;
  1194         SwitchSurface();
  1201         iExtDisplayConnType = aExtDisplayConnType;
       
  1202         
       
  1203         if(prevExtDisplayConnType == EExtDisplayConnectionProviderConnTypeDisconnected)
       
  1204             {
       
  1205             // disconnected -> connected  - don't care which type it is
       
  1206             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected disconnected -> connected(type %d)", iExtDisplayConnType);
       
  1207             iExtDisplayConnected = ETrue;
       
  1208             SwitchSurface();
       
  1209             }
       
  1210         else if(iExtDisplayConnType == EExtDisplayConnectionProviderConnTypeDisconnected)
       
  1211             {
       
  1212             // connected -> disconnected  - don't care from which type it is
       
  1213             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected connected(type %d) -> disconnected", prevExtDisplayConnType);
       
  1214             iExtDisplayConnected = EFalse;
       
  1215             SwitchSurface();
       
  1216             }
       
  1217         else
       
  1218             {
       
  1219             // If we get this far then the connection type has changed from "AV Out -> HDMI" or "HDMI -> AV Out"
       
  1220             // Both are likely. "AV Out -> HDMI" occurs if AV Out cable is connected and HDMI cable is then connected.
       
  1221             // "HDMI -> AV Out" occurs if both AV Out and HDMI cables are connected and HDMI cable is then disconnected.
       
  1222             // HDMI is preferred over AV Out.
       
  1223         
       
  1224             // update external display window data
       
  1225             iExtDisplayHandler->UpdateWindow();
       
  1226             TRect externalDisplayRect(TPoint(0, 0), iExtDisplayHandler->DisplaySizeInPixels());
       
  1227             (*iWindowsArrayPtr)[0].iClipRect = externalDisplayRect;
       
  1228             (*iWindowsArrayPtr)[0].iVideoExtent = externalDisplayRect;
       
  1229             TRAPD(err, (*iWindowsArrayPtr)[0].iAutoScaleType = ExtDisplayAutoScaleTypeL());
       
  1230             if(err == KErrNone)
       
  1231                 {
       
  1232                 RemoveBackgroundSurface(ETrue);
       
  1233                 RedrawWindows(iCropRegion);
       
  1234                 }
       
  1235             else
       
  1236                 {
       
  1237                 // Not a lot we can do. Just keep as it is but external display output will be incorrect. 
       
  1238                 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ExtDisplayAutoScaleTypeL failed %d", err);
       
  1239                 }
       
  1240             }
  1195 	    }
  1241 	    }
  1196 	else
  1242 	else
  1197 	    {
  1243         {
  1198 	    DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change in ext display connection status");
  1244         DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change to connection type");
  1199 	    }
  1245         }
  1200 	
  1246 	
  1201 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---");
  1247 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---");
  1202 	}
  1248 	}
  1203 
  1249 
  1204 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
  1250 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
  1233     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL - iWindow WsHandle 0x%X", windowData.iWindow->WsHandle());
  1279     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL - iWindow WsHandle 0x%X", windowData.iWindow->WsHandle());
  1234     
  1280     
  1235     TRect externalDisplayRect(TPoint(0, 0), extDisplayHandler->DisplaySizeInPixels());
  1281     TRect externalDisplayRect(TPoint(0, 0), extDisplayHandler->DisplaySizeInPixels());
  1236     windowData.iClipRect = externalDisplayRect;
  1282     windowData.iClipRect = externalDisplayRect;
  1237     windowData.iVideoExtent = externalDisplayRect;
  1283     windowData.iVideoExtent = externalDisplayRect;
  1238     // windowData.iScaleWidth not required for EAutoScaleBestFit
  1284     // windowData.iScaleWidth only required for EAutoScaleNone
  1239     // windowData.iScaleHeight not required for EAutoScaleBestFit
  1285     // windowData.iScaleWidth only required for EAutoScaleNone
  1240     windowData.iRotation = EVideoRotationNone;
  1286     windowData.iRotation = EVideoRotationNone;
  1241     windowData.iAutoScaleType = EAutoScaleBestFit;
  1287     windowData.iAutoScaleType = ExtDisplayAutoScaleTypeL();
  1242     windowData.iHorizPos = EHorizontalAlignCenter;
  1288     windowData.iHorizPos = EHorizontalAlignCenter;
  1243     windowData.iVertPos = EVerticalAlignCenter;
  1289     windowData.iVertPos = EVerticalAlignCenter;
  1244     // windowData.iWindow2 not used        
  1290     // windowData.iWindow2 not used        
  1245     
  1291     
  1246     iExtDisplayWindows.AppendL(windowData);
  1292     iExtDisplayWindows.AppendL(windowData);
  1269     
  1315     
  1270     if(iExtDisplayConnectionProvider)
  1316     if(iExtDisplayConnectionProvider)
  1271         {
  1317         {
  1272         iExtDisplaySwitchingSupported = ETrue;
  1318         iExtDisplaySwitchingSupported = ETrue;
  1273         iExtDisplayConnectionProvider->SetExtDisplayConnectionProviderCallback(*this);
  1319         iExtDisplayConnectionProvider->SetExtDisplayConnectionProviderCallback(*this);
  1274         iExtDisplayConnected = iExtDisplayConnectionProvider->ExtDisplayConnected();
  1320         iExtDisplayConnType = iExtDisplayConnectionProvider->ExtDisplayConnType();
       
  1321         iExtDisplayConnected = (iExtDisplayConnType != EExtDisplayConnectionProviderConnTypeDisconnected);
  1275         }
  1322         }
  1276 
  1323 
  1277     DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL ---");
  1324     DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL ---");
  1278     }
  1325     }
  1279 
  1326 
  1506 	aOldRect.Intersection(aOtherRect);
  1553 	aOldRect.Intersection(aOtherRect);
  1507 	aNewRect.Intersection(aOtherRect);
  1554 	aNewRect.Intersection(aOtherRect);
  1508 
  1555 
  1509 	if (aOldRect != aNewRect)
  1556 	if (aOldRect != aNewRect)
  1510 		{
  1557 		{
  1511 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged - Intersection area has changed");
  1558 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged --- Intersection area has changed");
  1512 		return ETrue;
  1559 		return ETrue;
  1513 		}
  1560 		}
  1514 
  1561 
  1515 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged - Intersection area has not changed");
  1562 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged --- Intersection area has not changed");
  1516 	return EFalse;
  1563 	return EFalse;
  1517 	}
  1564 	}
       
  1565 
       
  1566 /**
       
  1567 * This function calculates the delta width and delta height for AV out when the TV-Out setting is set to "widescreen".
       
  1568 *
       
  1569 * AV out has fixed resolution whether TV-Out is set to "normal" or "widescreen". The TV-Out setting indicates
       
  1570 * that the video should be scaled so that when displayed on a corresponding TV the aspect looks correct.
       
  1571 * 
       
  1572 * When displaying video on a widescreen TV through AV out, because the resolution is the same the TV stretches
       
  1573 * the video horizontally. When displaying on a normal TV no stretching takes place.
       
  1574 * 
       
  1575 * For "normal" TAutoScaleType::EAutoScaleClip is used.
       
  1576 * 
       
  1577 * For "widescreen" this function calculates the width delta and height delta required so that when the video is stretched
       
  1578 * the aspect looks correct on a widescreen TV.
       
  1579 * 
       
  1580 * This function must only be called when autoscale is set to TAutoScaleType::EAutoScaleStretch and an external display is
       
  1581 * connected.
       
  1582 **/
       
  1583 void CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay(TReal32 aViewportAspect, const TRect& aVideoExtent, TInt& aDeltaHeight, TInt& aDeltaWidth)
       
  1584     {
       
  1585     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay +++");
       
  1586     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aViewportAspect %f", aViewportAspect);
       
  1587     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
       
  1588     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aDeltaHeight %d", aDeltaHeight);
       
  1589     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aDeltaWidth %d", aDeltaWidth);
       
  1590 
       
  1591     aDeltaWidth = 0;
       
  1592     aDeltaHeight = 0;
       
  1593     
       
  1594     TReal32 wideScreenAspect = (TReal32)16 / (TReal32)9;
       
  1595     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay wideScreenAspect %f", wideScreenAspect);
       
  1596 
       
  1597     if(aViewportAspect == wideScreenAspect)
       
  1598         {
       
  1599         // no need to calculate
       
  1600         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect equals wideScreenAspect");
       
  1601         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - width delta and height delta not changed");
       
  1602         }
       
  1603     else if(aViewportAspect < wideScreenAspect)
       
  1604         {
       
  1605         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect is less than wideScreenAspect");
       
  1606         
       
  1607         // calculate video width for viewport that when stretched looks ok on widescreen
       
  1608         TReal32 correctedWidth = (TReal32)aVideoExtent.Width() * aViewportAspect / wideScreenAspect;
       
  1609         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay corrected viewport width %f", correctedWidth);
       
  1610         
       
  1611         aDeltaWidth = correctedWidth - aVideoExtent.Width();
       
  1612         }
       
  1613     else // aViewportAspect > wideScreenAspect
       
  1614         {
       
  1615         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect is greater than wideScreenAspect");
       
  1616 
       
  1617         // calculate video height for viewport that when stretched looks ok on widescreen
       
  1618         TReal32 correctedHeight = (TReal32)aVideoExtent.Height() * wideScreenAspect / aViewportAspect;
       
  1619         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay corrected viewport height %f", correctedHeight);
       
  1620         
       
  1621         aDeltaHeight = aVideoExtent.Height() - correctedHeight;
       
  1622         }        
       
  1623     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay --- aDeltaHeight %d", aDeltaHeight);
       
  1624     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay --- aDeltaWidth %d", aDeltaWidth);
       
  1625     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay ---");
       
  1626     }
       
  1627 
       
  1628 TBool CMediaClientVideoDisplayBody::IsWideScreenL()
       
  1629     {
       
  1630     DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsWideScreenL +++");
       
  1631     
       
  1632     CRepository* repo = CRepository::NewLC(KCRUidTvoutSettings);
       
  1633     TInt value;
       
  1634     User::LeaveIfError(repo->Get(KSettingsTvAspectRatio, value));
       
  1635 
       
  1636     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsWideScreenL Tv Apect Ratio set to %d, 0=4x3 1=16x9", value);
       
  1637 
       
  1638     CleanupStack::PopAndDestroy(repo);
       
  1639     
       
  1640     TBool ret = value > 0;
       
  1641     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsWideScreenL --- return %d", ret);
       
  1642     return ret;
       
  1643     }
       
  1644 
       
  1645 TAutoScaleType CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL()
       
  1646     {
       
  1647     DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL +++");
       
  1648     
       
  1649     // EExtDisplayConnectionProviderConnTypeHdmi - EAutoScaleBestFit
       
  1650     // EExtDisplayConnectionProviderConnTypeAnalog / normal - EAutoScaleBestFit
       
  1651     // EExtDisplayConnectionProviderConnTypeAnalog / widescreen - EAutoScaleStretch
       
  1652     
       
  1653     TAutoScaleType autoScaleType;
       
  1654     if((iExtDisplayConnType == EExtDisplayConnectionProviderConnTypeAnalog) && IsWideScreenL())
       
  1655         {
       
  1656         DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL External display scale type EAutoScaleStretch");
       
  1657         autoScaleType = EAutoScaleStretch;
       
  1658         }
       
  1659     else
       
  1660         {
       
  1661         DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL External display scale type EAutoScaleBestFit");
       
  1662         autoScaleType = EAutoScaleBestFit;
       
  1663         }
       
  1664     
       
  1665     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL --- return %d", autoScaleType);
       
  1666     return autoScaleType;
       
  1667     }