mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp
changeset 0 40261b775718
child 7 94dbab0a2133
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "mediaclientvideodisplaybody.h"
       
    17 #include "mediaclientvideotrace.h"
       
    18 #include <surfaceeventhandler.h>
       
    19 
       
    20 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId)
       
    21 	{
       
    22 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL +++"));
       
    23 	CMediaClientVideoDisplayBody* self = new (ELeave) CMediaClientVideoDisplayBody(aDisplayId);
       
    24 	CleanupStack::PushL(self);
       
    25 	self->ConstructL();
       
    26 	CleanupStack::Pop(self);
       
    27 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL ---"));
       
    28 	return self;
       
    29 	}
       
    30 
       
    31 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId,
       
    32 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
       
    33 	{
       
    34 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL +++"));
       
    35 	if(aSurfaceId.IsNull())
       
    36 		{
       
    37 		User::Leave(KErrArgument);
       
    38 		}
       
    39 	CMediaClientVideoDisplayBody* self = new(ELeave) CMediaClientVideoDisplayBody(aDisplayId, aSurfaceId, aCropRect, aAspectRatio);
       
    40 	CleanupStack::PushL(self);
       
    41 	self->ConstructL();
       
    42 	CleanupStack::Pop();
       
    43 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL ---"));
       
    44 	return self;
       
    45 	}
       
    46 
       
    47 void CMediaClientVideoDisplayBody::ConstructL()
       
    48 	{
       
    49 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConstructL +++"));
       
    50 	
       
    51 	iExtDisplaySwitchingSupported = CExtDisplayConnectionProviderInterface::ExternalDisplaySupportedL();
       
    52 	
       
    53 	// Try and enable display switching by default. If this leaves then do so quietly.
       
    54 	// Either the client has no scheduler installed or the device does not support external
       
    55 	// switching (i.e. no plugin was found) 
       
    56 	TRAPD(err, SetExternalDisplaySwitchingL(ETrue));
       
    57 	err = err; // remove compile warning
       
    58 	DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::ConstructL SetExternalDisplaySwitchingL returned with %d"), err);
       
    59 	
       
    60 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConstructL ---"));
       
    61 	}
       
    62 
       
    63 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId, const TSurfaceId& aSurfaceId,
       
    64 		const TRect& aCropRect, TVideoAspectRatio aAspectRatio) :
       
    65 	iDisplayId(aDisplayId),
       
    66 	iSurfaceId(aSurfaceId),
       
    67 	iCropRect(aCropRect),
       
    68 	iAspectRatio(aAspectRatio)
       
    69 	{	
       
    70 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++"));
       
    71 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---"));
       
    72 	}
       
    73 
       
    74 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId) :
       
    75 	iDisplayId(aDisplayId)
       
    76 	{	
       
    77 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++"));
       
    78 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---"));
       
    79 	}
       
    80 
       
    81 CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody()
       
    82 	{
       
    83 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody +++"));
       
    84 
       
    85 	RemoveBackgroundSurface(ETrue);
       
    86 		
       
    87 	iWindows.Close();	
       
    88 	delete iExtDisplayConnectionProvider;
       
    89 	REComSession::FinalClose();
       
    90 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody ---"));
       
    91 	}
       
    92 
       
    93 void CMediaClientVideoDisplayBody::AddDisplayL(MMMFSurfaceEventHandler& aEventHandler)
       
    94 	{
       
    95 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayL +++"));
       
    96 	if (iEventHandler != NULL)
       
    97 		{
       
    98 		User::Leave(KErrInUse);
       
    99 		}
       
   100 		
       
   101 	iEventHandler = &aEventHandler;
       
   102 	
       
   103 	if (IsSurfaceCreated())
       
   104 		{
       
   105 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
       
   106 		}
       
   107 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayL ---"));
       
   108 	}
       
   109 	
       
   110 void CMediaClientVideoDisplayBody::AddDisplayWindowL(const RWindowBase* aWindow, const TRect& aClipRect, const TRect& aCropRegion, const TRect& aVideoExtent, 
       
   111 															TReal32 aScaleWidth, TReal32 aScaleHeight, TVideoRotation aRotation, 
       
   112 															TAutoScaleType aAutoScaleType, TInt aHorizPos, TInt aVertPos, RWindow* aWindow2)
       
   113 	{
       
   114 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayWindowL +++"));
       
   115 	TInt pos = iWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
       
   116 	
       
   117 	if (pos != KErrNotFound)
       
   118 		{
       
   119 		User::Leave(KErrInUse);
       
   120 		}
       
   121 	
       
   122 	TWindowData winData(aWindow, aClipRect, aVideoExtent, aScaleWidth, aScaleHeight, aRotation, aAutoScaleType, aHorizPos, aVertPos, aWindow2);
       
   123 	iWindows.AppendL(winData);
       
   124 	
       
   125 	iCropRegion = aCropRegion;
       
   126 	
       
   127 	if (IsSurfaceCreated())
       
   128 		{
       
   129         if(iExtDisplaySwitchingSupported && iClientRequestedExtDisplaySwitching)
       
   130             {
       
   131             CreateExtDisplayConnProvAndRemoveSurfaceL(EFalse);
       
   132             }
       
   133         
       
   134         if(!iExtDisplayConnected)
       
   135             {
       
   136             User::LeaveIfError(SetBackgroundSurface(winData, aCropRegion));
       
   137             }
       
   138 		}
       
   139 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayWindowL ---"));
       
   140 	}
       
   141 
       
   142 void CMediaClientVideoDisplayBody::RemoveDisplay()
       
   143 	{
       
   144 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplay +++"));
       
   145 	iEventHandler = NULL;
       
   146 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplay ---"));
       
   147 	}	
       
   148 
       
   149 TInt CMediaClientVideoDisplayBody::RemoveDisplayWindow(const RWindowBase& aWindow)
       
   150 	{
       
   151 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++"));
       
   152 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   153 	
       
   154 	if (pos >= 0)
       
   155 		{
       
   156 		if (IsSurfaceCreated())
       
   157 			{
       
   158 			iWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
       
   159 
       
   160 			// Make sure all window rendering has completed before proceeding
       
   161 			RWsSession* ws = iWindows[pos].iWindow->Session();
       
   162 			if (ws)
       
   163 				{
       
   164 				ws->Finish();
       
   165 				}
       
   166 			}
       
   167 		iWindows.Remove(pos);
       
   168 		
       
   169 		if(iWindows.Count() == 0)
       
   170 		    {
       
   171 		    RemoveExtDisplayConnProv();
       
   172 		    }
       
   173 		}
       
   174 	
       
   175 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplayWindow ---"));
       
   176 	return pos;
       
   177 	}
       
   178 
       
   179 
       
   180 TInt CMediaClientVideoDisplayBody::SurfaceCreated(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio, const TRect& aCropRegion)
       
   181 	{
       
   182 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceCreated +++"));
       
   183 	TBool emitEvent = EFalse;
       
   184 	if((iSurfaceId != aSurfaceId) && (!aSurfaceId.IsNull()))
       
   185 		{
       
   186 		emitEvent = ETrue;
       
   187 		}
       
   188 
       
   189 	iSurfaceId = aSurfaceId;
       
   190 	iCropRect = aCropRect;
       
   191 	iAspectRatio = aAspectRatio;
       
   192 	iCropRegion = aCropRegion;
       
   193 	
       
   194 	if (emitEvent && iEventHandler)
       
   195 		{
       
   196 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
       
   197 		}
       
   198 
       
   199 	TInt err = KErrNone;
       
   200     if(iExtDisplaySwitchingSupported && iClientRequestedExtDisplaySwitching)
       
   201         {
       
   202         TRAP(err, CreateExtDisplayConnProvAndRemoveSurfaceL(EFalse));
       
   203         }
       
   204     
       
   205     if(!iExtDisplayConnected)
       
   206         {
       
   207         err = RedrawWindows(aCropRegion);
       
   208         }
       
   209     
       
   210     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceCreated ---"));
       
   211 	return err;
       
   212 	}
       
   213 
       
   214 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
       
   215 	{
       
   216 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveBackgroundSurface +++"));
       
   217 	if (IsSurfaceCreated())
       
   218 		{
       
   219 		TInt count = iWindows.Count();
       
   220 	
       
   221 		RWsSession* ws = NULL;
       
   222 		for (TInt i = 0; i < count; ++i)
       
   223 			{
       
   224 			iWindows[i].iWindow->RemoveBackgroundSurface(aTriggerRedraw);
       
   225 			// Make sure all window rendering has completed before proceeding
       
   226 			ws = iWindows[i].iWindow->Session();
       
   227 			if (ws)
       
   228 				{
       
   229 				ws->Finish();
       
   230 				}
       
   231 			}
       
   232 		}
       
   233 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveBackgroundSurface ---"));
       
   234 	}
       
   235 
       
   236 void CMediaClientVideoDisplayBody::RemoveSurface(TBool aControllerEvent)
       
   237     {
       
   238     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveSurface +++"));
       
   239     if (IsSurfaceCreated())
       
   240         {
       
   241         if(!iExtDisplayConnected)
       
   242             {
       
   243             RemoveBackgroundSurface(ETrue);
       
   244             }
       
   245         
       
   246         if (iEventHandler  && aControllerEvent)
       
   247             {
       
   248             iEventHandler->MmsehRemoveSurface(iSurfaceId);
       
   249             }
       
   250 
       
   251         iSurfaceId = TSurfaceId::CreateNullId();
       
   252 
       
   253         RemoveExtDisplayConnProv();
       
   254         }
       
   255     
       
   256     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveSurface ---"));
       
   257     }
       
   258 
       
   259 TInt CMediaClientVideoDisplayBody::SurfaceParametersChanged(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
       
   260 	{
       
   261 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceParametersChanged +++"));
       
   262 	if (!IsSurfaceCreated())
       
   263 		{
       
   264 		return KErrNotSupported;
       
   265 		}
       
   266 
       
   267 	if (iSurfaceId != aSurfaceId)
       
   268 		{
       
   269 		return KErrInUse;
       
   270 		}
       
   271 	
       
   272 	iCropRect = aCropRect;
       
   273 	iAspectRatio = aAspectRatio;
       
   274 	
       
   275 	if (iEventHandler)
       
   276 		{
       
   277 		iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, iCropRect, iAspectRatio);
       
   278 		}
       
   279 
       
   280 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceParametersChanged ---"));
       
   281 	return KErrNone;
       
   282 	}
       
   283 	
       
   284 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
       
   285 	{
       
   286 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RedrawWindows +++"));
       
   287 	TInt err = KErrNone;	
       
   288 
       
   289 	iCropRegion = aCropRegion;
       
   290 	
       
   291 	if(IsSurfaceCreated())
       
   292 		{
       
   293 		TInt count = iWindows.Count();
       
   294 	
       
   295 		for (TInt i = 0; i < count; ++i)
       
   296 			{
       
   297 			err = SetBackgroundSurface(iWindows[i], aCropRegion);
       
   298 		
       
   299 			if (err != KErrNone)
       
   300 				{
       
   301 				break;
       
   302 				}
       
   303 			}
       
   304 		}
       
   305 		
       
   306 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RedrawWindows ---"));
       
   307 	return err;
       
   308 	}
       
   309 
       
   310 void CMediaClientVideoDisplayBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
       
   311 	{
       
   312 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL +++"));
       
   313 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   314 	User::LeaveIfError(pos);
       
   315 	
       
   316 	iWindows[pos].iAutoScaleType = aScaleType;
       
   317 	iWindows[pos].iHorizPos = aHorizPos;
       
   318 	iWindows[pos].iVertPos = aVertPos;
       
   319 	iCropRegion = aCropRegion;
       
   320 	
       
   321 	if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   322 		{
       
   323 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   324 		}
       
   325 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL ---"));
       
   326 	}
       
   327 	
       
   328 
       
   329 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
       
   330 	{
       
   331 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL +++"));
       
   332 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   333 	User::LeaveIfError(pos);
       
   334 	
       
   335 	iWindows[pos].iRotation = aRotation;
       
   336 	iCropRegion = aCropRegion;
       
   337 	
       
   338     if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   339 		{
       
   340 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   341 		}
       
   342 	
       
   343 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL ---"));
       
   344 	}
       
   345 
       
   346 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
       
   347 	{
       
   348 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RotationL +++"));
       
   349 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   350 	User::LeaveIfError(pos);
       
   351 	
       
   352 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RotationL ---"));
       
   353 	return iWindows[pos].iRotation;
       
   354 	}
       
   355 
       
   356 void CMediaClientVideoDisplayBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
       
   357 	{
       
   358 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL +++"));
       
   359 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   360 	User::LeaveIfError(pos);
       
   361 	
       
   362 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
       
   363 		{
       
   364 		User::Leave(KErrArgument);
       
   365 		}
       
   366 
       
   367 	
       
   368 	iWindows[pos].iScaleWidth = aWidthPercentage;
       
   369 	iWindows[pos].iScaleHeight = aHeightPercentage;
       
   370 	iWindows[pos].iAutoScaleType = EAutoScaleNone;
       
   371 	iCropRegion = aCropRegion;
       
   372 	
       
   373     if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   374 		{
       
   375 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   376 		}
       
   377 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL ---"));
       
   378 	}
       
   379 	
       
   380 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
       
   381 	{
       
   382 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::GetScaleFactorL +++"));
       
   383 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   384 	User::LeaveIfError(pos);
       
   385 	
       
   386 	aWidthPercentage = iWindows[pos].iScaleWidth;
       
   387 	aHeightPercentage = iWindows[pos].iScaleHeight;
       
   388 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::GetScaleFactorL ---"));
       
   389 	}
       
   390 
       
   391 void CMediaClientVideoDisplayBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
       
   392 	{
       
   393 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL +++"));
       
   394 	
       
   395 	iCropRegion = aCropRegion;
       
   396 	TInt count = iWindows.Count();
       
   397 	
       
   398 	for (TInt i = 0; i < count; ++i)
       
   399 		{
       
   400 		iWindows[i].iAutoScaleType = aScaleType;
       
   401 		iWindows[i].iHorizPos = aHorizPos;
       
   402 		iWindows[i].iVertPos = aVertPos;
       
   403 	    if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   404 			{
       
   405 			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
       
   406 			}
       
   407 		}
       
   408 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL ---"));
       
   409 	}
       
   410 
       
   411 
       
   412 void CMediaClientVideoDisplayBody::SetRotationL(TVideoRotation aRotation, const TRect& aCropRegion)
       
   413 	{
       
   414 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL +++"));
       
   415 	iCropRegion = aCropRegion;
       
   416 	TInt count = iWindows.Count();
       
   417 	
       
   418 	for (TInt i = 0; i < count; ++i)
       
   419 		{
       
   420 		iWindows[i].iRotation = aRotation;
       
   421 	    if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   422 			{
       
   423 			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
       
   424 			}
       
   425 		}
       
   426 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL ---"));
       
   427 	}
       
   428 		
       
   429 void CMediaClientVideoDisplayBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
       
   430 	{
       
   431 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL +++"));
       
   432 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
       
   433 		{
       
   434 		User::Leave(KErrArgument);
       
   435 		}
       
   436 	
       
   437 	iCropRegion = aCropRegion;
       
   438 	TInt count = iWindows.Count();
       
   439 	
       
   440 	for (TInt i = 0; i < count; ++i)
       
   441 		{
       
   442 		iWindows[i].iScaleWidth = aWidthPercentage;
       
   443 		iWindows[i].iScaleHeight = aHeightPercentage;
       
   444 		iWindows[i].iAutoScaleType = EAutoScaleNone;
       
   445 	    if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   446 			{
       
   447 			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
       
   448 			}
       
   449 		}
       
   450 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL ---"));
       
   451 	}
       
   452 
       
   453 void CMediaClientVideoDisplayBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect, const TRect& aCropRegion)
       
   454 	{
       
   455 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetWindowClipRectL +++"));
       
   456 	
       
   457 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   458 	User::LeaveIfError(pos);
       
   459 	
       
   460 	iWindows[pos].iClipRect = aWindowClipRect;
       
   461 	iCropRegion = aCropRegion;
       
   462 	
       
   463     if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   464 		{
       
   465 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   466 		}
       
   467 	
       
   468 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetWindowClipRectL ---"));
       
   469 	}
       
   470 	
       
   471 void CMediaClientVideoDisplayBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent, const TRect& aCropRegion)
       
   472 	{
       
   473 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetVideoExtentL +++"));
       
   474 	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
       
   475 	User::LeaveIfError(pos);
       
   476 	
       
   477 	iWindows[pos].iVideoExtent = aVideoExtent;
       
   478 	iCropRegion = aCropRegion;
       
   479 	
       
   480     if (IsSurfaceCreated() && !iExtDisplayConnected)
       
   481 		{
       
   482 		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
       
   483 		}
       
   484 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetVideoExtentL ---"));
       
   485 	}
       
   486 	
       
   487 TBool CMediaClientVideoDisplayBody::HasWindows() const
       
   488 	{
       
   489 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::HasWindows +++"));
       
   490 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::HasWindows ---"));
       
   491 	return (iWindows.Count() > 0);
       
   492 	}
       
   493 	
       
   494 TInt CMediaClientVideoDisplayBody::SetBackgroundSurface(TWindowData& aWindowData,  
       
   495 									const TRect& aCropRegion)
       
   496 	{
       
   497 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetBackgroundSurface +++"));
       
   498 	
       
   499 	// required as this private function is called directly from external friend class
       
   500 	iCropRegion = aCropRegion;
       
   501 
       
   502     // viewport is the viewable area of surface
       
   503     TRect viewport(iCropRect);
       
   504     if (aCropRegion.Width() > 0 || aCropRegion.Height() > 0)
       
   505         {
       
   506         viewport.Intersection(aCropRegion);
       
   507         }
       
   508     
       
   509     // Viewport is 0 size, don't show any video
       
   510     if (viewport.Width() <= 0 || viewport.Height() <= 0)
       
   511         {
       
   512         return KErrArgument;
       
   513         }
       
   514 
       
   515 	TRect extent;
       
   516 	CalculateExtentAndViewport(aWindowData, extent, viewport);
       
   517 	
       
   518 	aWindowData.iSurfaceConfig.SetViewport(viewport);
       
   519 	aWindowData.iSurfaceConfig.SetExtent(extent);
       
   520 	aWindowData.iSurfaceConfig.SetOrientation(ConvertRotation(aWindowData.iRotation));
       
   521 	
       
   522 	aWindowData.iSurfaceConfig.SetSurfaceId(iSurfaceId);
       
   523 	
       
   524 	// Get the rectangle that bounds the crop rectangle and the viewport.  This should be
       
   525 	// the same as the crop rectangle as long as the viewport does not go outside this area.
       
   526 	TRect rect(iCropRect);
       
   527 	rect.BoundingRect(viewport);
       
   528 	TInt err = KErrNone;
       
   529 	
       
   530 	// Check if the viewport and extent can be displayed as a background surface. The viewport 
       
   531 	// is valid if it is within the crop rectangle and is not empty.  The extent is valid if 
       
   532 	// it is not empty. 
       
   533 	if (rect == iCropRect && !viewport.IsEmpty() && !extent.IsEmpty())
       
   534 		{
       
   535 		err = aWindowData.iWindow->SetBackgroundSurface(aWindowData.iSurfaceConfig, ETrue);
       
   536 		}
       
   537 
       
   538 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetBackgroundSurface ---"));
       
   539 	return err;
       
   540 	}
       
   541 
       
   542 void CMediaClientVideoDisplayBody::CalculateExtentAndViewport(const TWindowData& aWindowData, TRect& aExtent, TRect& aViewport)
       
   543     {
       
   544     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CalculateExtentAndViewport +++"));
       
   545 
       
   546     TRect videoExtent(aWindowData.iVideoExtent);
       
   547     
       
   548     TReal32 inputWidth = 0.0f;
       
   549     TReal32 inputHeight = 0.0f;
       
   550     TReal32 pixelAspectRatio = 0.0f;
       
   551     switch (aWindowData.iRotation)
       
   552         {
       
   553         case EVideoRotationNone:
       
   554         case EVideoRotationClockwise180:
       
   555             inputWidth = static_cast<TReal32>(aViewport.Width());
       
   556             inputHeight = static_cast<TReal32>(aViewport.Height());
       
   557             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iNumerator) / iAspectRatio.iDenominator;
       
   558             break;
       
   559         case EVideoRotationClockwise90:
       
   560         case EVideoRotationClockwise270:
       
   561             inputWidth = static_cast<TReal32>(aViewport.Height());
       
   562             inputHeight = static_cast<TReal32>(aViewport.Width());
       
   563             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iDenominator) / iAspectRatio.iNumerator;
       
   564             break;
       
   565         default:
       
   566             // Should never get to default unless there's been some programming error.
       
   567             User::Invariant();
       
   568             break;
       
   569         }
       
   570         
       
   571     TReal32 viewportAspect = pixelAspectRatio * inputWidth / inputHeight;
       
   572     TReal32 vidextAspect = static_cast<TReal32>(videoExtent.Width()) / static_cast<TReal32>(videoExtent.Height());
       
   573     
       
   574     // Set the extent to the display area in the window.  The final height and with is to 
       
   575     // be changed by deltaHeight and deltaWidth respectively.
       
   576     aExtent = videoExtent;
       
   577     
       
   578     TInt deltaHeight = 0;
       
   579     TInt deltaWidth = 0;
       
   580     
       
   581     if (aWindowData.iAutoScaleType == EAutoScaleBestFit)
       
   582         {
       
   583         if (viewportAspect > vidextAspect)
       
   584             {
       
   585             // Shrink height to get the correct aspect ratio
       
   586             deltaHeight = (TInt) (aExtent.Width() / viewportAspect - aExtent.Height());
       
   587             }
       
   588         else
       
   589             {
       
   590             // Shrink width to get the correct aspect ratio
       
   591             deltaWidth = (TInt) (aExtent.Height() * viewportAspect - aExtent.Width());
       
   592             }
       
   593         }
       
   594     else if (aWindowData.iAutoScaleType == EAutoScaleClip)
       
   595         {
       
   596         if (viewportAspect > vidextAspect)
       
   597             {
       
   598             // Expand width to get the correct aspect ratio
       
   599             deltaWidth = (TInt) (aExtent.Height() * viewportAspect - aExtent.Width());
       
   600             }
       
   601         else
       
   602             {
       
   603             // Expand height to get the correct aspect ratio
       
   604             deltaHeight = (TInt) (aExtent.Width() / viewportAspect - aExtent.Height());
       
   605             }
       
   606         }
       
   607     else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
       
   608         {
       
   609         // Don't do anything: the extent is already set to the size of the video extent.
       
   610         }
       
   611     else if (aWindowData.iAutoScaleType == EAutoScaleNone)
       
   612         {
       
   613         // for non-square pixels, reduce one dimension
       
   614         // TBD other option is to enlarge in the other dimension
       
   615         if(pixelAspectRatio > 1)
       
   616             {
       
   617             inputHeight /= pixelAspectRatio;
       
   618             }
       
   619         else if(pixelAspectRatio < 1)
       
   620             {
       
   621             inputWidth *= pixelAspectRatio;
       
   622             }
       
   623         deltaHeight = (TInt) (inputHeight * aWindowData.iScaleHeight * 0.01 - videoExtent.Height());
       
   624         deltaWidth = (TInt) (inputWidth * aWindowData.iScaleWidth * 0.01 - videoExtent.Width());
       
   625         }
       
   626     
       
   627     // Change the width of the extent in the proper directions and propertions.
       
   628     switch (aWindowData.iHorizPos)
       
   629         {
       
   630     case EHorizontalAlignCenter:
       
   631         aExtent.iTl.iX -= deltaWidth / 2;
       
   632         aExtent.iBr.iX += deltaWidth / 2;
       
   633         break;
       
   634     case EHorizontalAlignLeft:
       
   635         aExtent.iBr.iX += deltaWidth;
       
   636         break;
       
   637     case EHorizontalAlignRight:
       
   638         aExtent.iTl.iX -= deltaWidth;
       
   639         break;
       
   640     default:
       
   641         TInt width = aExtent.Width() + deltaWidth;
       
   642         aExtent.iTl.iX += aWindowData.iHorizPos;
       
   643         aExtent.iBr.iX = aExtent.iTl.iX + width;
       
   644         break;
       
   645         }
       
   646     
       
   647     // Change the height of the extent in the proper directions and propertions.
       
   648     switch (aWindowData.iVertPos)
       
   649         {
       
   650     case EVerticalAlignCenter:
       
   651         aExtent.iTl.iY -= deltaHeight / 2;
       
   652         aExtent.iBr.iY += deltaHeight / 2;
       
   653         break;
       
   654     case EVerticalAlignTop:
       
   655         aExtent.iBr.iY += deltaHeight;
       
   656         break;
       
   657     case EVerticalAlignBottom:
       
   658         aExtent.iTl.iY -= deltaHeight;
       
   659         break;
       
   660     default:
       
   661         TInt height = aExtent.Height() + deltaHeight;
       
   662         aExtent.iTl.iY += aWindowData.iVertPos;
       
   663         aExtent.iBr.iY = aExtent.iTl.iY + height;
       
   664         break;
       
   665         }
       
   666         
       
   667     // The video should not be displayed outside the intended video extent or clipping rectangle.  
       
   668     // The extent already has the correct size and position for displaying the entire viewport.  
       
   669     // The viewport is clipped such that the video is not moved/distorted when we take the extent 
       
   670     // to be the intersection of itself and the intended video extent.
       
   671     
       
   672     TRect viewableArea(videoExtent);
       
   673     viewableArea.Intersection(aWindowData.iClipRect);
       
   674     
       
   675     // Number of pixels (in window coordinates) to be clipped on the right, bottom, top and left sides of
       
   676     // the video.
       
   677     TInt dr = Max(0, aExtent.iBr.iX - viewableArea.iBr.iX);
       
   678     TInt db = Max(0, aExtent.iBr.iY - viewableArea.iBr.iY);
       
   679     TInt dt = Max(0, viewableArea.iTl.iY - aExtent.iTl.iY);
       
   680     TInt dl = Max(0, viewableArea.iTl.iX - aExtent.iTl.iX);
       
   681     
       
   682     // Calculate the number of pixels in the video per window pixel in both x and y directions.
       
   683     TReal32 wRatio = 0.0f; 
       
   684     TReal32 hRatio = 0.0f;
       
   685     
       
   686     // Make sure we don't divide by 0
       
   687     if (aExtent.Width() != 0)
       
   688         {
       
   689         wRatio = inputWidth / static_cast<TReal32>(aExtent.Width());
       
   690         }
       
   691     
       
   692     if (aExtent.Height() != 0)
       
   693         {
       
   694         hRatio = inputHeight / static_cast<TReal32>(aExtent.Height());
       
   695         }
       
   696     
       
   697     // Clip the viewport 
       
   698     switch (aWindowData.iRotation)
       
   699         {
       
   700         case EVideoRotationNone:
       
   701             aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dr));
       
   702             aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(db));
       
   703             aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dl));
       
   704             aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dt));
       
   705             break;
       
   706         case EVideoRotationClockwise180:
       
   707             aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dl));
       
   708             aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dt));
       
   709             aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dr));
       
   710             aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(db));
       
   711             break;
       
   712         case EVideoRotationClockwise90:
       
   713             aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(db));
       
   714             aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dl));
       
   715             aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dt));
       
   716             aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dr));
       
   717             break;
       
   718         case EVideoRotationClockwise270:
       
   719             aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dt));
       
   720             aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dr));
       
   721             aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(db));
       
   722             aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dl));
       
   723             break;
       
   724         default:
       
   725             // Should never get to default unless there's been some programming error.
       
   726             User::Invariant();
       
   727             break;
       
   728         }
       
   729     
       
   730     // Clip the extent.
       
   731     aExtent.Intersection(viewableArea);
       
   732     
       
   733     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CalculateExtentAndViewport ---"));
       
   734     }
       
   735 
       
   736 TBool CMediaClientVideoDisplayBody::IsUsed() const
       
   737 	{
       
   738 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsUsed +++"));
       
   739 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsUsed ---"));
       
   740 	return (iEventHandler != NULL || iWindows.Count() > 0);
       
   741 	}
       
   742 	
       
   743 
       
   744 TBool CMediaClientVideoDisplayBody::IsSurfaceCreated() const
       
   745 	{
       
   746 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsSurfaceCreated +++"));
       
   747 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsSurfaceCreated ---"));
       
   748 	return !(iSurfaceId.IsNull());
       
   749 	}
       
   750 		
       
   751 TInt CMediaClientVideoDisplayBody::DisplayId() const
       
   752 	{
       
   753 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::DisplayId +++"));
       
   754 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::DisplayId ---"));
       
   755 	return iDisplayId;
       
   756 	}
       
   757 	
       
   758 TInt CMediaClientVideoDisplayBody::CompareByDisplay(const TInt* aDisplayId, const CMediaClientVideoDisplayBody& aDisplay)
       
   759 	{
       
   760 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CompareByDisplay +++"));
       
   761 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CompareByDisplay ---"));
       
   762 	return (*aDisplayId - aDisplay.DisplayId());
       
   763 	}
       
   764 		
       
   765 TInt CMediaClientVideoDisplayBody::Compare(const CMediaClientVideoDisplayBody& aLeft, const CMediaClientVideoDisplayBody& aRight)
       
   766 	{
       
   767 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Compare +++"));
       
   768 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Compare ---"));
       
   769 	return (aLeft.DisplayId() - aRight.DisplayId());
       
   770 	}
       
   771 	
       
   772 CFbsBitGc::TGraphicsOrientation CMediaClientVideoDisplayBody::ConvertRotation(TVideoRotation aRotation)
       
   773 	{
       
   774 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConvertRotation +++"));
       
   775 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConvertRotation ---"));
       
   776 	switch(aRotation)
       
   777 		{
       
   778 		case EVideoRotationNone:
       
   779 			return CFbsBitGc::EGraphicsOrientationNormal;
       
   780 		case EVideoRotationClockwise90:
       
   781 			return CFbsBitGc::EGraphicsOrientationRotated270;
       
   782 		case EVideoRotationClockwise180:
       
   783 			return CFbsBitGc::EGraphicsOrientationRotated180;
       
   784 		case EVideoRotationClockwise270:
       
   785 			return CFbsBitGc::EGraphicsOrientationRotated90;
       
   786 		default:
       
   787 			// Should never get to default unless there's been some programming error.
       
   788 			User::Invariant();
       
   789 			// This is never reached, just to keep the compiler happy
       
   790 			return CFbsBitGc::EGraphicsOrientationNormal;
       
   791 		}
       
   792 	}
       
   793 
       
   794 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::FindDisplayWithWindowL(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, const RWindowBase& aWindow)
       
   795 	{
       
   796 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::FindDisplayWithWindowL +++"));
       
   797 	TInt count = aDisplays.Count();
       
   798 	
       
   799 	for (TInt i = 0; i < count; ++i)
       
   800 		{
       
   801 		CMediaClientVideoDisplayBody* display = aDisplays[i];
       
   802 	
       
   803 		if (display->iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle) != KErrNotFound)
       
   804 			{
       
   805 			DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::FindDisplayWithWindowL ---"));
       
   806 			return display;	
       
   807 			}
       
   808 		}
       
   809 		
       
   810 	User::Leave(KErrNotFound);
       
   811 	return NULL;
       
   812 	}
       
   813 	
       
   814 RArray<CMediaClientVideoDisplayBody::TWindowData>& CMediaClientVideoDisplayBody::Windows()
       
   815 	{
       
   816 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Windows +++"));
       
   817 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Windows ---"));
       
   818 	return iWindows;	
       
   819 	}
       
   820 
       
   821 void CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL(TRect& aExtent, TRect& aViewport, TRect& aExternalDisplayRect)
       
   822     {
       
   823     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL +++"));
       
   824     
       
   825     TWindowData windowData;
       
   826     windowData.iVideoExtent = aExternalDisplayRect;
       
   827     windowData.iRotation = EVideoRotationNone;
       
   828     windowData.iAutoScaleType = EAutoScaleBestFit;
       
   829     windowData.iHorizPos = EHorizontalAlignCenter;
       
   830     windowData.iVertPos = EVerticalAlignCenter;
       
   831     windowData.iClipRect = aExternalDisplayRect;
       
   832     
       
   833     aViewport = iCropRect;
       
   834     // Viewport is 0 size, don't show any video
       
   835     if (aViewport.Width() <= 0 || aViewport.Height() <= 0)
       
   836         {
       
   837         User::Leave(KErrArgument);
       
   838         }
       
   839     
       
   840     CalculateExtentAndViewport(windowData, aExtent, aViewport);
       
   841     
       
   842     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL ---"));
       
   843     }
       
   844 
       
   845 void CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL(TBool aRemoveBackgroundSurface)
       
   846     {
       
   847     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL +++"));
       
   848 
       
   849     if((iExtDisplayConnectionProvider == NULL) && (iWindows.Count() > 0))
       
   850         {
       
   851         iExtDisplayConnectionProvider = CExtDisplayConnectionProviderInterface::NewL(*this, iSurfaceId);
       
   852         iExtDisplayConnected = iExtDisplayConnectionProvider->ExtDisplayConnectedL();
       
   853         
       
   854         if(iExtDisplayConnected && aRemoveBackgroundSurface)
       
   855             {
       
   856             RemoveBackgroundSurface(ETrue);
       
   857             }
       
   858         }
       
   859 
       
   860     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL ---"));
       
   861     }
       
   862    
       
   863 void CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL()
       
   864     {
       
   865     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL +++"));
       
   866 
       
   867     if(iExtDisplayConnectionProvider != NULL)
       
   868         {
       
   869         delete iExtDisplayConnectionProvider;
       
   870         REComSession::FinalClose();
       
   871         iExtDisplayConnectionProvider = NULL;
       
   872         iExtDisplayConnected = EFalse;
       
   873         User::LeaveIfError(RedrawWindows(iCropRegion));
       
   874         }
       
   875 
       
   876     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL ---"));
       
   877     }
       
   878 
       
   879 void CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv()
       
   880     {
       
   881     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv +++"));
       
   882 
       
   883     if(iExtDisplayConnectionProvider != NULL)
       
   884         {
       
   885         delete iExtDisplayConnectionProvider;
       
   886         REComSession::FinalClose();
       
   887         iExtDisplayConnectionProvider = NULL;
       
   888         iExtDisplayConnected = EFalse;
       
   889         }
       
   890 
       
   891     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv ---"));
       
   892     }
       
   893 
       
   894 void CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL(TBool aControl)
       
   895     {
       
   896     DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL +++ aControl=%d"), aControl);
       
   897 
       
   898     // not supported
       
   899     if(!iExtDisplaySwitchingSupported)
       
   900         {
       
   901         User::Leave(KErrNotSupported);
       
   902         }
       
   903     
       
   904     // need active scheduler installed
       
   905     if(CActiveScheduler::Current() == NULL)
       
   906         {
       
   907         User::Leave(KErrNotReady);
       
   908         }
       
   909 
       
   910     if(iClientRequestedExtDisplaySwitching != aControl)
       
   911         {
       
   912         iClientRequestedExtDisplaySwitching = aControl;
       
   913         
       
   914         if(IsSurfaceCreated())
       
   915             {
       
   916             if(iClientRequestedExtDisplaySwitching)
       
   917                 {
       
   918                 CreateExtDisplayConnProvAndRemoveSurfaceL(ETrue);
       
   919                 }
       
   920             else
       
   921                 {
       
   922                 RemoveExtDisplayConnProvAndRedrawL();
       
   923                 }
       
   924             }
       
   925         else
       
   926             {
       
   927             DEBUG_PRINT(_L("No Surface exists"));
       
   928             }
       
   929         }
       
   930     
       
   931     DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---"));
       
   932     }
       
   933 
       
   934 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TBool aExtDisplayConnected)
       
   935 	{
       
   936 	DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d"), aExtDisplayConnected);
       
   937 	
       
   938 	if(iExtDisplayConnected != aExtDisplayConnected)
       
   939 	    {
       
   940 	    iExtDisplayConnected = aExtDisplayConnected;
       
   941 	    if(iExtDisplayConnected)
       
   942 	        {
       
   943 	        RemoveBackgroundSurface(ETrue);
       
   944 	        }
       
   945 	    else
       
   946 	        {
       
   947 	        // ignore error - no need to tell provider - but lets log it in case it fails
       
   948 	        TInt err = RedrawWindows(iCropRegion);
       
   949 	        DEBUG_PRINT2(_L("RedrawWindows returned with %d"), err);
       
   950 	        }
       
   951 	    }
       
   952 	else
       
   953 	    {
       
   954 	    DEBUG_PRINT(_L("No change in ext display connection status"));
       
   955 	    }
       
   956 	
       
   957 	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---"));
       
   958 	}