mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp
changeset 26 c36d67f77f75
parent 15 c1e808730d6c
child 31 ae0addfe117e
equal deleted inserted replaced
15:c1e808730d6c 26:c36d67f77f75
    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;
       
    27 
       
    28 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
       
    29 // make sure that off screen is bottom right and not top left. This makes it more efficient for GCE backend
       
    30 // to render
       
    31 const TInt KHiddenExtentA = 2000; // rect Ax and Ay co-ordinate used to set extent off screen
       
    32 const TInt KHiddenExtentB = 2001; // rect Bx and By co-ordinate used to set extent off screen
       
    33 #endif
    23 
    34 
    24 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, TBool aExtDisplaySwitchingControl)
    35 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, TBool aExtDisplaySwitchingControl)
    25 	{
    36 	{
    26 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
    37 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
    27     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
    38     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
    38 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId,
    49 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId,
    39 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio, TBool aExtDisplaySwitchingControl)
    50 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio, TBool aExtDisplaySwitchingControl)
    40 	{
    51 	{
    41 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
    52 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
    42 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
    53 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
    43     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aSurfaceId 0x%X,0x%X,0x%X,0x%X", aSurfaceId.iInternal[0], aSurfaceId.iInternal[1], aSurfaceId.iInternal[2], aSurfaceId.iInternal[3]);
    54     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aSurfaceId %08x:%08x:%08x:%08x", aSurfaceId.iInternal[3], aSurfaceId.iInternal[2], aSurfaceId.iInternal[1], aSurfaceId.iInternal[0]);
    44     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
    55     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
    45     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::NewL - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
    56     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::NewL - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
    46     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aExtDisplaySwitchingControl %d", aExtDisplaySwitchingControl);
    57     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aExtDisplaySwitchingControl %d", aExtDisplaySwitchingControl);
    47 
    58 
    48 	if(aSurfaceId.IsNull())
    59 	if(aSurfaceId.IsNull())
   119 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody +++");
   130 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody +++");
   120 
   131 
   121 	// remove for whichever array is current
   132 	// remove for whichever array is current
   122 	RemoveBackgroundSurface(ETrue);
   133 	RemoveBackgroundSurface(ETrue);
   123 
   134 
       
   135 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
       
   136     if(iSwitchedToExternalDisplay)
       
   137         {
       
   138         SetWindowArrayPtr2Client();
       
   139         RemoveBackgroundSurface(ETrue);
       
   140         }
       
   141 #endif
       
   142 
   124 	iClientWindows.Close();	
   143 	iClientWindows.Close();	
   125     iExtDisplayWindows.Close(); 
   144     iExtDisplayWindows.Close(); 
   126 
   145 
   127 	delete iExtDisplayHandler;
   146 	delete iExtDisplayHandler;
   128 	RemoveExtDisplayPlugin();
   147 	RemoveExtDisplayPlugin();
   199             {
   218             {
   200             TRAPD(err, CreateExtDisplayHandlerL());
   219             TRAPD(err, CreateExtDisplayHandlerL());
   201             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL CreateExtDisplayHandlerL error %d", err);
   220             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL CreateExtDisplayHandlerL error %d", err);
   202             if(err == KErrNone)
   221             if(err == KErrNone)
   203                 {
   222                 {
       
   223 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
       
   224                 // attach surface to client window and hide
       
   225                 // ignore error - no handling required
       
   226                 SetHiddenBackgroundSurfaceOnClientWindow(winData);
       
   227 #endif                
       
   228                 // handle external display
   204                 SetWindowArrayPtr2Ext();
   229                 SetWindowArrayPtr2Ext();
   205                 User::LeaveIfError(RedrawWindows(aCropRegion));
   230                 User::LeaveIfError(RedrawWindows(aCropRegion));
   206                 }
   231                 }
   207             }
   232             }
   208         
   233         
   226 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++");
   251 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++");
   227 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   252 	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
   228 	
   253 	
   229 	if (pos >= 0)
   254 	if (pos >= 0)
   230 	    {
   255 	    {
       
   256 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
       
   257         if(IsSurfaceCreated())
       
   258 #else
   231 	    if(IsSurfaceCreated() && !iSwitchedToExternalDisplay)
   259 	    if(IsSurfaceCreated() && !iSwitchedToExternalDisplay)
   232             {
   260 #endif
       
   261 	        {
   233             iClientWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
   262             iClientWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
   234             // Make sure all window rendering has completed before proceeding
   263             // Make sure all window rendering has completed before proceeding
   235             RWsSession* ws = iClientWindows[pos].iWindow->Session();
   264             RWsSession* ws = iClientWindows[pos].iWindow->Session();
   236             if (ws)
   265             if (ws)
   237                 {
   266                 {
   261 
   290 
   262 
   291 
   263 TInt CMediaClientVideoDisplayBody::SurfaceCreated(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio, const TRect& aCropRegion)
   292 TInt CMediaClientVideoDisplayBody::SurfaceCreated(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio, const TRect& aCropRegion)
   264 	{
   293 	{
   265 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated +++");
   294 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated +++");
   266     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aSurfaceId 0x%X,0x%X,0x%X,0x%X", aSurfaceId.iInternal[0], aSurfaceId.iInternal[1], aSurfaceId.iInternal[2], aSurfaceId.iInternal[3]);
   295     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aSurfaceId %08x:%08x:%08x:%08x", aSurfaceId.iInternal[3], aSurfaceId.iInternal[2], aSurfaceId.iInternal[1], aSurfaceId.iInternal[0]);
   267     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
   296     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
   268     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
   297     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
   269     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   298     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
   270 
   299 
   271     TBool emitEvent = EFalse;
   300     TBool emitEvent = EFalse;
   296             {
   325             {
   297             TRAP(err, CreateExtDisplayHandlerL());
   326             TRAP(err, CreateExtDisplayHandlerL());
   298             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated CreateExtDisplayHandlerL error %d", err);
   327             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated CreateExtDisplayHandlerL error %d", err);
   299             if(err == KErrNone)
   328             if(err == KErrNone)
   300                 {
   329                 {
       
   330 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
       
   331                 SetHiddenBackgroundSurfaceOnAllClientWindows();
       
   332 #endif          
   301                 SetWindowArrayPtr2Ext();
   333                 SetWindowArrayPtr2Ext();
   302                 }
   334                 }
   303             }
   335             }
   304         }
   336         }
   305     
   337     
   310 	}
   342 	}
   311 
   343 
   312 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
   344 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
   313 	{
   345 	{
   314 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveBackgroundSurface +++");
   346 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveBackgroundSurface +++");
       
   347     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::RemoveBackgroundSurface - iSurfaceId %08x:%08x:%08x:%08x", iSurfaceId.iInternal[3], iSurfaceId.iInternal[2], iSurfaceId.iInternal[1], iSurfaceId.iInternal[0]);
       
   348 
   315 	if (IsSurfaceCreated())
   349 	if (IsSurfaceCreated())
   316 		{
   350 		{
   317 		RWsSession* ws = NULL;
   351 		RWsSession* ws = NULL;
   318 		TInt count = iWindowsArrayPtr->Count();
   352 		TInt count = iWindowsArrayPtr->Count();
   319 	
   353 	
   332 	}
   366 	}
   333 
   367 
   334 void CMediaClientVideoDisplayBody::RemoveSurface(TBool aControllerEvent)
   368 void CMediaClientVideoDisplayBody::RemoveSurface(TBool aControllerEvent)
   335     {
   369     {
   336     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface +++");
   370     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface +++");
       
   371     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::RemoveSurface - iSurfaceId %08x:%08x:%08x:%08x", iSurfaceId.iInternal[3], iSurfaceId.iInternal[2], iSurfaceId.iInternal[1], iSurfaceId.iInternal[0]);
       
   372 
   337     if (IsSurfaceCreated())
   373     if (IsSurfaceCreated())
   338         {
   374         {
   339         RemoveBackgroundSurface(ETrue);
   375         RemoveBackgroundSurface(ETrue);
   340 
   376 
   341         if (iEventHandler  && aControllerEvent)
   377         if (iEventHandler  && aControllerEvent)
   342             {
   378             {
   343             iEventHandler->MmsehRemoveSurface(iSurfaceId);
   379             iEventHandler->MmsehRemoveSurface(iSurfaceId);
   344             }
   380             }
   345 
   381 
       
   382         if(iSwitchedToExternalDisplay)
       
   383             {
       
   384             SetWindowArrayPtr2Client();
       
   385 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
       
   386             RemoveBackgroundSurface(ETrue);
       
   387 #endif
       
   388             RemoveExtDisplayHandler();
       
   389             }
   346         iSurfaceId = TSurfaceId::CreateNullId();
   390         iSurfaceId = TSurfaceId::CreateNullId();
   347 
       
   348         if(iSwitchedToExternalDisplay)
       
   349             {
       
   350             SetWindowArrayPtr2Client();
       
   351             RemoveExtDisplayHandler();
       
   352             }
       
   353         }
   391         }
   354     
   392     
   355     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface ---");
   393     DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface ---");
   356     }
   394     }
   357 
   395 
   358 TInt CMediaClientVideoDisplayBody::SurfaceParametersChanged(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
   396 TInt CMediaClientVideoDisplayBody::SurfaceParametersChanged(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
   359 	{
   397 	{
   360 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged +++");
   398 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged +++");
   361     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aSurfaceId 0x%X,0x%X,0x%X,0x%X", aSurfaceId.iInternal[0], aSurfaceId.iInternal[1], aSurfaceId.iInternal[2], aSurfaceId.iInternal[3]);
   399     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aSurfaceId %08x:%08x:%08x:%08x", aSurfaceId.iInternal[3], aSurfaceId.iInternal[2], aSurfaceId.iInternal[1], aSurfaceId.iInternal[0]);
   362     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
   400     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
   363     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
   401     DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
   364 
   402 
   365     if (!IsSurfaceCreated())
   403     if (!IsSurfaceCreated())
   366 		{
   404 		{
   832         }
   870         }
   833 
   871 
   834     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport1 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
   872     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport1 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
   835 
   873 
   836     TRect videoExtent(aWindowData.iVideoExtent);
   874     TRect videoExtent(aWindowData.iVideoExtent);
   837     
   875 
   838     TReal32 inputWidth = 0.0f;
   876     TReal32 inputWidth = 0.0f;
   839     TReal32 inputHeight = 0.0f;
   877     TReal32 inputHeight = 0.0f;
   840     TReal32 pixelAspectRatio = 0.0f;
   878     TReal32 pixelAspectRatio = 0.0f;
   841     switch (aWindowData.iRotation)
   879     switch (aWindowData.iRotation)
   842         {
   880         {
   897             deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
   935             deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
   898             }
   936             }
   899         }
   937         }
   900     else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
   938     else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
   901         {
   939         {
   902         // Don't do anything: the extent is already set to the size of the video extent.
   940         if(iSwitchedToExternalDisplay)
       
   941             {
       
   942             UpdateDeltaForExtDisplay(viewportAspect, videoExtent, deltaHeight, deltaWidth);
       
   943             }
   903         }
   944         }
   904     else if (aWindowData.iAutoScaleType == EAutoScaleNone)
   945     else if (aWindowData.iAutoScaleType == EAutoScaleNone)
   905         {
   946         {
   906         // for non-square pixels, reduce one dimension
   947         // for non-square pixels, reduce one dimension
   907         // TBD other option is to enlarge in the other dimension
   948         // TBD other option is to enlarge in the other dimension
  1040     aWindowData.iSurfaceConfig.SetViewport(viewport);
  1081     aWindowData.iSurfaceConfig.SetViewport(viewport);
  1041     aWindowData.iSurfaceConfig.SetExtent(extent);
  1082     aWindowData.iSurfaceConfig.SetExtent(extent);
  1042     aWindowData.iSurfaceConfig.SetOrientation(ConvertRotation(aWindowData.iRotation));
  1083     aWindowData.iSurfaceConfig.SetOrientation(ConvertRotation(aWindowData.iRotation));
  1043     
  1084     
  1044     aWindowData.iSurfaceConfig.SetSurfaceId(iSurfaceId);
  1085     aWindowData.iSurfaceConfig.SetSurfaceId(iSurfaceId);
       
  1086 
       
  1087     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - iSurfaceId %08x:%08x:%08x:%08x",
       
  1088             iSurfaceId.iInternal[3], iSurfaceId.iInternal[2], iSurfaceId.iInternal[1], iSurfaceId.iInternal[0]);
  1045     
  1089     
  1046     // Get the rectangle that bounds the crop rectangle and the viewport.  This should be
  1090     // Get the rectangle that bounds the crop rectangle and the viewport.  This should be
  1047     // the same as the crop rectangle as long as the viewport does not go outside this area.
  1091     // the same as the crop rectangle as long as the viewport does not go outside this area.
  1048     TRect rect(iCropRect);
  1092     TRect rect(iCropRect);
  1049     rect.BoundingRect(viewport);
  1093     rect.BoundingRect(viewport);
  1182         }
  1226         }
  1183     
  1227     
  1184     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
  1228     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
  1185     }
  1229     }
  1186 
  1230 
  1187 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TBool aExtDisplayConnected)
  1231 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TExtDisplayConnectionProviderConnType aExtDisplayConnType)
  1188 	{
  1232 	{
  1189 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d", aExtDisplayConnected);
  1233 	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnType=%d", aExtDisplayConnType);
  1190 	
  1234 	
  1191 	if(iExtDisplayConnected != aExtDisplayConnected)
  1235 	if(aExtDisplayConnType != iExtDisplayConnType)
  1192 	    {
  1236 	    {
  1193 	    iExtDisplayConnected = aExtDisplayConnected;
  1237         TExtDisplayConnectionProviderConnType prevExtDisplayConnType = iExtDisplayConnType;
  1194         SwitchSurface();
  1238         iExtDisplayConnType = aExtDisplayConnType;
       
  1239         
       
  1240         if(prevExtDisplayConnType == EExtDisplayConnectionProviderConnTypeDisconnected)
       
  1241             {
       
  1242             // disconnected -> connected  - don't care which type it is
       
  1243             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected disconnected -> connected(type %d)", iExtDisplayConnType);
       
  1244             iExtDisplayConnected = ETrue;
       
  1245             SwitchSurface();
       
  1246             }
       
  1247         else if(iExtDisplayConnType == EExtDisplayConnectionProviderConnTypeDisconnected)
       
  1248             {
       
  1249             // connected -> disconnected  - don't care from which type it is
       
  1250             DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected connected(type %d) -> disconnected", prevExtDisplayConnType);
       
  1251             iExtDisplayConnected = EFalse;
       
  1252             SwitchSurface();
       
  1253             }
       
  1254         else
       
  1255             {
       
  1256             // If we get this far then the connection type has changed from "AV Out -> HDMI" or "HDMI -> AV Out"
       
  1257             // Both are likely. "AV Out -> HDMI" occurs if AV Out cable is connected and HDMI cable is then connected.
       
  1258             // "HDMI -> AV Out" occurs if both AV Out and HDMI cables are connected and HDMI cable is then disconnected.
       
  1259             // HDMI is preferred over AV Out.
       
  1260         
       
  1261             // update external display window data
       
  1262             iExtDisplayHandler->UpdateWindow();
       
  1263             TRect externalDisplayRect(TPoint(0, 0), iExtDisplayHandler->DisplaySizeInPixels());
       
  1264             (*iWindowsArrayPtr)[0].iClipRect = externalDisplayRect;
       
  1265             (*iWindowsArrayPtr)[0].iVideoExtent = externalDisplayRect;
       
  1266             TRAPD(err, (*iWindowsArrayPtr)[0].iAutoScaleType = ExtDisplayAutoScaleTypeL());
       
  1267             if(err == KErrNone)
       
  1268                 {
       
  1269                 RemoveBackgroundSurface(ETrue);
       
  1270                 RedrawWindows(iCropRegion);
       
  1271                 }
       
  1272             else
       
  1273                 {
       
  1274                 // Not a lot we can do. Just keep as it is but external display output will be incorrect. 
       
  1275                 DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ExtDisplayAutoScaleTypeL failed %d", err);
       
  1276                 }
       
  1277             }
  1195 	    }
  1278 	    }
  1196 	else
  1279 	else
  1197 	    {
  1280         {
  1198 	    DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change in ext display connection status");
  1281         DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change to connection type");
  1199 	    }
  1282         }
  1200 	
  1283 	
  1201 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---");
  1284 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---");
  1202 	}
  1285 	}
  1203 
  1286 
  1204 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
  1287 void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
  1233     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL - iWindow WsHandle 0x%X", windowData.iWindow->WsHandle());
  1316     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL - iWindow WsHandle 0x%X", windowData.iWindow->WsHandle());
  1234     
  1317     
  1235     TRect externalDisplayRect(TPoint(0, 0), extDisplayHandler->DisplaySizeInPixels());
  1318     TRect externalDisplayRect(TPoint(0, 0), extDisplayHandler->DisplaySizeInPixels());
  1236     windowData.iClipRect = externalDisplayRect;
  1319     windowData.iClipRect = externalDisplayRect;
  1237     windowData.iVideoExtent = externalDisplayRect;
  1320     windowData.iVideoExtent = externalDisplayRect;
  1238     // windowData.iScaleWidth not required for EAutoScaleBestFit
  1321     // windowData.iScaleWidth only required for EAutoScaleNone
  1239     // windowData.iScaleHeight not required for EAutoScaleBestFit
  1322     // windowData.iScaleWidth only required for EAutoScaleNone
  1240     windowData.iRotation = EVideoRotationNone;
  1323     windowData.iRotation = EVideoRotationNone;
  1241     windowData.iAutoScaleType = EAutoScaleBestFit;
  1324     windowData.iAutoScaleType = ExtDisplayAutoScaleTypeL();
  1242     windowData.iHorizPos = EHorizontalAlignCenter;
  1325     windowData.iHorizPos = EHorizontalAlignCenter;
  1243     windowData.iVertPos = EVerticalAlignCenter;
  1326     windowData.iVertPos = EVerticalAlignCenter;
  1244     // windowData.iWindow2 not used        
  1327     // windowData.iWindow2 not used        
  1245     
  1328     
  1246     iExtDisplayWindows.AppendL(windowData);
  1329     iExtDisplayWindows.AppendL(windowData);
  1269     
  1352     
  1270     if(iExtDisplayConnectionProvider)
  1353     if(iExtDisplayConnectionProvider)
  1271         {
  1354         {
  1272         iExtDisplaySwitchingSupported = ETrue;
  1355         iExtDisplaySwitchingSupported = ETrue;
  1273         iExtDisplayConnectionProvider->SetExtDisplayConnectionProviderCallback(*this);
  1356         iExtDisplayConnectionProvider->SetExtDisplayConnectionProviderCallback(*this);
  1274         iExtDisplayConnected = iExtDisplayConnectionProvider->ExtDisplayConnected();
  1357         iExtDisplayConnType = iExtDisplayConnectionProvider->ExtDisplayConnType();
       
  1358         iExtDisplayConnected = (iExtDisplayConnType != EExtDisplayConnectionProviderConnTypeDisconnected);
  1275         }
  1359         }
  1276 
  1360 
  1277     DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL ---");
  1361     DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL ---");
  1278     }
  1362     }
  1279 
  1363 
  1378         {
  1462         {
  1379         TRAPD(err, CreateExtDisplayHandlerL());
  1463         TRAPD(err, CreateExtDisplayHandlerL());
  1380         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface CreateExtDisplayHandlerL error %d", err);
  1464         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SwitchSurface CreateExtDisplayHandlerL error %d", err);
  1381         if(err == KErrNone)
  1465         if(err == KErrNone)
  1382             {
  1466             {
  1383             // Set background surface for external display window before removing from client windows.
       
  1384             // Required for switching of paused video
       
  1385             SetWindowArrayPtr2Ext();
  1467             SetWindowArrayPtr2Ext();
  1386             RedrawWindows(iCropRegion);
  1468             RedrawWindows(iCropRegion); 
       
  1469             
       
  1470 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
       
  1471             // Hide surface so that video is not seen on client window
       
  1472             HideAllClientWindows();
       
  1473 #else
       
  1474             // Surface removed from window
  1387             SetWindowArrayPtr2Client();
  1475             SetWindowArrayPtr2Client();
  1388             RemoveBackgroundSurface(ETrue);
  1476             RemoveBackgroundSurface(ETrue);
  1389             SetWindowArrayPtr2Ext();
  1477             SetWindowArrayPtr2Ext();
       
  1478 #endif
  1390             }
  1479             }
  1391         }
  1480         }
  1392     else if(iSwitchedToExternalDisplay)
  1481     else if(iSwitchedToExternalDisplay)
  1393         {
  1482         {
  1394         // Set background surface for clientwindows before removing from external display window.
  1483         // Set background surface for clientwindows before removing from external display window.
  1395         // Required for switching of paused video
       
  1396         SetWindowArrayPtr2Client();
  1484         SetWindowArrayPtr2Client();
       
  1485         // RedrawWindows handles both the case where the surface was removed from client window and 
       
  1486         // also the case where the surface was hidden from client window
  1397         RedrawWindows(iCropRegion);
  1487         RedrawWindows(iCropRegion);
  1398         SetWindowArrayPtr2Ext();
  1488         SetWindowArrayPtr2Ext();
  1399         RemoveBackgroundSurface(ETrue);
  1489         RemoveBackgroundSurface(ETrue);
  1400         RemoveExtDisplayHandler();
  1490         RemoveExtDisplayHandler();
  1401         SetWindowArrayPtr2Client();
  1491         SetWindowArrayPtr2Client();
  1506 	aOldRect.Intersection(aOtherRect);
  1596 	aOldRect.Intersection(aOtherRect);
  1507 	aNewRect.Intersection(aOtherRect);
  1597 	aNewRect.Intersection(aOtherRect);
  1508 
  1598 
  1509 	if (aOldRect != aNewRect)
  1599 	if (aOldRect != aNewRect)
  1510 		{
  1600 		{
  1511 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged - Intersection area has changed");
  1601 		DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged --- Intersection area has changed");
  1512 		return ETrue;
  1602 		return ETrue;
  1513 		}
  1603 		}
  1514 
  1604 
  1515 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged - Intersection area has not changed");
  1605 	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IntersectionAreaChanged --- Intersection area has not changed");
  1516 	return EFalse;
  1606 	return EFalse;
  1517 	}
  1607 	}
       
  1608 
       
  1609 /**
       
  1610 * This function calculates the delta width and delta height for AV out when the TV-Out setting is set to "widescreen".
       
  1611 *
       
  1612 * AV out has fixed resolution whether TV-Out is set to "normal" or "widescreen". The TV-Out setting indicates
       
  1613 * that the video should be scaled so that when displayed on a corresponding TV the aspect looks correct.
       
  1614 * 
       
  1615 * When displaying video on a widescreen TV through AV out, because the resolution is the same the TV stretches
       
  1616 * the video horizontally. When displaying on a normal TV no stretching takes place.
       
  1617 * 
       
  1618 * For "normal" TAutoScaleType::EAutoScaleClip is used.
       
  1619 * 
       
  1620 * For "widescreen" this function calculates the width delta and height delta required so that when the video is stretched
       
  1621 * the aspect looks correct on a widescreen TV.
       
  1622 * 
       
  1623 * This function must only be called when autoscale is set to TAutoScaleType::EAutoScaleStretch and an external display is
       
  1624 * connected.
       
  1625 **/
       
  1626 void CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay(TReal32 aViewportAspect, const TRect& aVideoExtent, TInt& aDeltaHeight, TInt& aDeltaWidth)
       
  1627     {
       
  1628     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay +++");
       
  1629     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aViewportAspect %f", aViewportAspect);
       
  1630     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
       
  1631     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aDeltaHeight %d", aDeltaHeight);
       
  1632     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay aDeltaWidth %d", aDeltaWidth);
       
  1633 
       
  1634     aDeltaWidth = 0;
       
  1635     aDeltaHeight = 0;
       
  1636     
       
  1637     TReal32 wideScreenAspect = (TReal32)16 / (TReal32)9;
       
  1638     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay wideScreenAspect %f", wideScreenAspect);
       
  1639 
       
  1640     if(aViewportAspect == wideScreenAspect)
       
  1641         {
       
  1642         // no need to calculate
       
  1643         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect equals wideScreenAspect");
       
  1644         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - width delta and height delta not changed");
       
  1645         }
       
  1646     else if(aViewportAspect < wideScreenAspect)
       
  1647         {
       
  1648         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect is less than wideScreenAspect");
       
  1649         
       
  1650         // calculate video width for viewport that when stretched looks ok on widescreen
       
  1651         TReal32 correctedWidth = (TReal32)aVideoExtent.Width() * aViewportAspect / wideScreenAspect;
       
  1652         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay corrected viewport width %f", correctedWidth);
       
  1653         
       
  1654         aDeltaWidth = correctedWidth - aVideoExtent.Width();
       
  1655         }
       
  1656     else // aViewportAspect > wideScreenAspect
       
  1657         {
       
  1658         DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay - Viewport Aspect is greater than wideScreenAspect");
       
  1659 
       
  1660         // calculate video height for viewport that when stretched looks ok on widescreen
       
  1661         TReal32 correctedHeight = (TReal32)aVideoExtent.Height() * wideScreenAspect / aViewportAspect;
       
  1662         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay corrected viewport height %f", correctedHeight);
       
  1663         
       
  1664         aDeltaHeight = aVideoExtent.Height() - correctedHeight;
       
  1665         }        
       
  1666     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay --- aDeltaHeight %d", aDeltaHeight);
       
  1667     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay --- aDeltaWidth %d", aDeltaWidth);
       
  1668     DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateDeltaForExtDisplay ---");
       
  1669     }
       
  1670 
       
  1671 TBool CMediaClientVideoDisplayBody::IsWideScreenL()
       
  1672     {
       
  1673     DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsWideScreenL +++");
       
  1674     
       
  1675     CRepository* repo = CRepository::NewLC(KCRUidTvoutSettings);
       
  1676     TInt value;
       
  1677     User::LeaveIfError(repo->Get(KSettingsTvAspectRatio, value));
       
  1678 
       
  1679     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsWideScreenL Tv Apect Ratio set to %d, 0=4x3 1=16x9", value);
       
  1680 
       
  1681     CleanupStack::PopAndDestroy(repo);
       
  1682     
       
  1683     TBool ret = value > 0;
       
  1684     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsWideScreenL --- return %d", ret);
       
  1685     return ret;
       
  1686     }
       
  1687 
       
  1688 TAutoScaleType CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL()
       
  1689     {
       
  1690     DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL +++");
       
  1691     
       
  1692     // EExtDisplayConnectionProviderConnTypeHdmi - EAutoScaleBestFit
       
  1693     // EExtDisplayConnectionProviderConnTypeAnalog / normal - EAutoScaleBestFit
       
  1694     // EExtDisplayConnectionProviderConnTypeAnalog / widescreen - EAutoScaleStretch
       
  1695     
       
  1696     TAutoScaleType autoScaleType;
       
  1697     if((iExtDisplayConnType == EExtDisplayConnectionProviderConnTypeAnalog) && IsWideScreenL())
       
  1698         {
       
  1699         DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL External display scale type EAutoScaleStretch");
       
  1700         autoScaleType = EAutoScaleStretch;
       
  1701         }
       
  1702     else
       
  1703         {
       
  1704         DEBUG_PRINTF("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL External display scale type EAutoScaleBestFit");
       
  1705         autoScaleType = EAutoScaleBestFit;
       
  1706         }
       
  1707     
       
  1708     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ExtDisplayAutoScaleTypeL --- return %d", autoScaleType);
       
  1709     return autoScaleType;
       
  1710     }
       
  1711 
       
  1712 #ifdef MEDIA_CLIENT_SURFACE_NOT_REMOVED_FROM_CLIENT_WINDOW
       
  1713 
       
  1714 void CMediaClientVideoDisplayBody::HideAllClientWindows()
       
  1715     {
       
  1716     DEBUG_PRINTF("CMediaClientVideoDisplayBody::HideAllClientWindows +++");
       
  1717 
       
  1718     TInt count = iClientWindows.Count();
       
  1719     for (TInt i = 0; i < count; ++i)
       
  1720         {
       
  1721         // ignore error - cannot be handled
       
  1722         HideWindow(iClientWindows[i].iWindow);
       
  1723         }
       
  1724     
       
  1725     DEBUG_PRINTF("CMediaClientVideoDisplayBody::HideAllClientWindows ---");
       
  1726     }
       
  1727 
       
  1728 TInt CMediaClientVideoDisplayBody::HideWindow(RWindowBase* aWindow)
       
  1729     {
       
  1730     DEBUG_PRINTF("CMediaClientVideoDisplayBody::HideWindow +++");
       
  1731 
       
  1732     TSurfaceConfiguration config;
       
  1733     TInt err = aWindow->GetBackgroundSurface(config);
       
  1734     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::HideWindow GetBackgroundSurface error %d", err);
       
  1735     
       
  1736 #ifdef _DEBUG
       
  1737     TSurfaceId surface;
       
  1738     config.GetSurfaceId(surface);
       
  1739     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::HideWindow - Retrieved Surface %08x:%08x:%08x:%08x", 
       
  1740             surface.iInternal[3], surface.iInternal[2], surface.iInternal[1], surface.iInternal[0]);
       
  1741 #endif
       
  1742     
       
  1743     if (err == KErrNone)
       
  1744         {
       
  1745         config.SetExtent(TRect(KHiddenExtentA, KHiddenExtentA, KHiddenExtentB, KHiddenExtentB));
       
  1746         err = aWindow->SetBackgroundSurface(config, ETrue);
       
  1747         // Make sure all window rendering has completed before proceeding
       
  1748         RWsSession* ws = aWindow->Session();
       
  1749         if (ws)
       
  1750            {
       
  1751            ws->Finish();
       
  1752            }
       
  1753         DEBUG_PRINTF2("CMediaClientVideoDisplayBody::HideWindow SetBackgroundSurface error %d", err);
       
  1754         }
       
  1755     
       
  1756     DEBUG_PRINTF("CMediaClientVideoDisplayBody::HideWindow ---");
       
  1757     return err;
       
  1758     }
       
  1759 
       
  1760 void CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnAllClientWindows()
       
  1761     {
       
  1762     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnAllClientWindows +++");
       
  1763 
       
  1764     TInt count = iClientWindows.Count();
       
  1765     for (TInt i = 0; i < count; ++i)
       
  1766         {
       
  1767         // ignore error - cannot be handled
       
  1768         SetHiddenBackgroundSurfaceOnClientWindow(iClientWindows[i]);
       
  1769         }
       
  1770     
       
  1771     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnAllClientWindows ---");
       
  1772     }
       
  1773 
       
  1774 
       
  1775 TInt CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnClientWindow(TWindowData& aWindowData)
       
  1776     {
       
  1777     DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnClientWindow +++");    
       
  1778     DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnClientWindow - iSurfaceId %08x:%08x:%08x:%08x",
       
  1779                 iSurfaceId.iInternal[3], iSurfaceId.iInternal[2], iSurfaceId.iInternal[1], iSurfaceId.iInternal[0]);
       
  1780     
       
  1781     TSurfaceConfiguration config;
       
  1782     config.SetExtent(TRect(KHiddenExtentA, KHiddenExtentA, KHiddenExtentB, KHiddenExtentB));   
       
  1783     config.SetSurfaceId(iSurfaceId);
       
  1784     TInt err = aWindowData.iWindow->SetBackgroundSurface(config, ETrue);
       
  1785     
       
  1786     DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetHiddenBackgroundSurfaceOnClientWindow ---, return %d", err);
       
  1787     return err;
       
  1788     }
       
  1789 #endif