Revision: 201007 RCL_3
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 12 Mar 2010 15:50:33 +0200
branchRCL_3
changeset 7 94dbab0a2133
parent 3 f7d9134af83e
child 8 bc06d8566074
Revision: 201007 Kit: 201008
devsound/a3fdevsound/src/devsoundadaptor/cdevaudiocontrol.cpp
devsound/a3fdevsound/src/devsoundadaptor/cdevcommoncontrol.cpp
devsound/a3fdevsound/src/devsoundadaptor/cdevrecordcontrol.cpp
imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/scripts/TSU_ICL_COD_03.script
imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestStep.cpp
imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestStep.h
imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestSuite.cpp
mdfdevvideoextensions/nga_mdf_postprocessor/inc/NGAPostProcHwDevice.h
mdfdevvideoextensions/nga_mdf_postprocessor/src/NGAPostProcHwDevice.cpp
mm_pub/drm_audio_player_api/tsrc/data/mmc/drm/test3gp.dcf
mm_pub/drm_audio_player_api/tsrc/data/mmc/drm/testmp3.dcf
mmlibs/mmfw/MMPFiles/client/MediaClientVideo.mmp
mmlibs/mmfw/MMPFiles/client/mediaclientvideodisplay.mmp
mmlibs/mmfw/inc/mmf/PLUGIN/mmfmediaclientextdisplayinterface.h
mmlibs/mmfw/src/Client/Video/mediaclientextdisplayhandler.cpp
mmlibs/mmfw/src/Client/Video/mediaclientextdisplayhandler.h
mmlibs/mmfw/src/Client/Video/mediaclientextdisplayinterface.cpp
mmlibs/mmfw/src/Client/Video/mediaclientvideodisplay.cpp
mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp
mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.h
mmlibs/mmfw/src/Client/Video/mediaclientvideotrace.h
mmlibs/mmfw/src/Client/Video/mmfclientvideoplayerbody.cpp
mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestRecorder.cpp
mmlibs/mmfw/tsrc/mmfunittest/MmpFiles/TSU_MMF_VCLNT_01.mmp
mmlibs/mmfw/tsrc/mmfunittest/VCLNT/TSU_MMF_VCLNT_01/TestStepUnitMMFVidClient.cpp
mmlibs/mmfw/tsrc/mmfunittest/aclnt/TSU_MMF_ACLNT_01/TestStepAudInStream.cpp
mmlibs/mmfw/tsrc/mmfunittest/aclnt/TSU_MMF_ACLNT_01/TestStepPlayerPlay.cpp
mmlibs/mmfw/tsrc/mmfunittest/ctlfrm/mp3/MmfMP3Format/101F7D99.rss
mmplugins/imagingplugins/codecs/GifCodec/GIFcodec.cpp
mmplugins/lib3gp/impl/src/file.cpp
mmtestenv/mmtesttools/Build/mmbuildrom.pl
--- a/devsound/a3fdevsound/src/devsoundadaptor/cdevaudiocontrol.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/devsound/a3fdevsound/src/devsoundadaptor/cdevaudiocontrol.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -937,7 +937,15 @@
 
 	if (aEvent == KUidA3FContextUpdateComplete)
 		{
-		iAdaptationObserver->AsynchronousOperationComplete(aError, ETrue);
+	        if(iIgnoreAsyncOpComplete)
+			{
+            	    	iAdaptationObserver->PreemptionFinishedCallbackReceived(ETrue);
+		    	iIgnoreAsyncOpComplete = EFalse;
+            	    	}
+        	else
+            	    	{
+                    	iAdaptationObserver->AsynchronousOperationComplete(aError, ETrue);
+                    	}
 		}
 	else if(aEvent == KUidA3FContextPreEmption || aEvent == KUidA3FContextPreEmptedCommit)
 		{
--- a/devsound/a3fdevsound/src/devsoundadaptor/cdevcommoncontrol.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/devsound/a3fdevsound/src/devsoundadaptor/cdevcommoncontrol.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -160,9 +160,9 @@
 
     if(iCallbackFromAdaptor == KCallbackNone)   
         {
+        iProcessingUnitError = aError;
         iCallbackFromAdaptor = KCallbackProcessingUnitError;
-        iAdaptationObserver->CallbackFromAdaptorReceived(KCallbackProcessingUnitError, KErrNone);
-        iProcessingUnitError = aError;
+        iAdaptationObserver->CallbackFromAdaptorReceived(KCallbackProcessingUnitError, aError);
         }
     else
         {
--- a/devsound/a3fdevsound/src/devsoundadaptor/cdevrecordcontrol.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/devsound/a3fdevsound/src/devsoundadaptor/cdevrecordcontrol.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -335,9 +335,6 @@
 // ---------------------------------------------------------------------------
 TBool CDevRecordControl::ProcessingError(TBool& aAyncOperation)
     {
-
-    iAdaptationObserver->RecordError(iProcessingUnitError);
-
     TInt err = iDevAudio->iAudioStream->Stop();
     if ( err == KErrNone)
         {
--- a/imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/scripts/TSU_ICL_COD_03.script	Sat Feb 20 00:20:15 2010 +0200
+++ b/imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/scripts/TSU_ICL_COD_03.script	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -525,3 +525,7 @@
 
 RUN_TEST_STEP -1, TSU_ICL_COD_03, MM-ICL-COD-U-5114-HP
 TEST_COMPLETE
+
+//AKAL-7YHLPR : Crash found in Themes Thread. Memory corruption with Gif image.
+RUN_TEST_STEP -1, TSU_ICL_COD_03, MM-ICL-COD-U-5108-HP
+TEST_COMPLETE
--- a/imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestStep.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestStep.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -10242,3 +10242,87 @@
     return EPass;
     }
 
+//AKAL-7YHLPR : Crash found in Themes Thread.
+RTestStep_5108::RTestStep_5108(CTestSuite* aSuite)
+    {
+    iSuite = aSuite;
+    iTestStepName = _L("MM-ICL-COD-U-5108-HP");
+    }
+
+
+void RTestStep_5108::Close()
+    {
+    delete iScheduler;
+    iScheduler = NULL;
+    iFs.Close();
+    RFbsSession::Disconnect();
+    }
+
+
+RTestStep_5108* RTestStep_5108::NewL(CTestSuite* aSuite)
+    {
+    if (!aSuite)
+        {
+        User::Leave(KErrArgument);        
+        }
+    return new(ELeave) RTestStep_5108(aSuite);
+    }
+
+
+TVerdict RTestStep_5108::OpenL()
+    {
+    User::LeaveIfError(RFbsSession::Connect());
+    User::LeaveIfError(iFs.Connect());
+
+    iScheduler = new(ELeave) CActiveScheduler();
+    CActiveScheduler::Install(iScheduler);
+    
+    return EPass;
+    }
+
+
+/*
+ * Test added for AKAL-7YHLPR : Crash found in Themes Thread.
+ * The test is to check the possible memory corruption on decoding a test Gif image. The gif image has transparency
+ * color index of 128. Decode option is Fast decode and with EColor64k. With these combination, the memory corruption 
+ * happens. The test decodes all the frames in the image.
+ * If memory corruption happens, the test will panic and fail. No panic means the problem is fixed, and the test passes.
+ * The test also fails if all frames are not decoded successfully. 
+ */
+TVerdict RTestStep_5108::DoTestStepL()
+    {
+    INFO_PRINTF1(_L("AKAL-7YHLPR : Crash found in Themes Thread."));
+    INFO_PRINTF1(_L("Test checks for memory corruption on decoding Gif image with Tranparency index = 128, with EColor64K and in Fast decode mode"));
+    _LIT(KGifTranpIdx128, "c:\\tsu_icl_cod_03\\secret.gif");
+    CImageDecoder* decoder = NULL;
+    //create decoder with Fast decode 
+    decoder = CImageDecoder::FileNewL(iFs, KGifTranpIdx128, CImageDecoder::EPreferFastDecode);
+    CleanupStack::PushL(decoder);
+    CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
+    //bitmap with EColor64K
+    TInt err = bitmap->Create(TSize(0,0), EColor64K);
+    CleanupStack::PushL(bitmap);
+    CActiveListener* listener = new (ELeave) CActiveListener;
+    CleanupStack::PushL(listener);//get the no. of frames in the image.
+    TInt frameCount = decoder->FrameCount();
+    TVerdict result = EPass;
+    //decode all the frames.
+    for(TInt i = 0; i < frameCount; i++)
+        {
+        const TFrameInfo& frameInfo = decoder->FrameInfo(i);
+        const TSize frameSize(frameInfo.iOverallSizeInPixels);
+        listener->InitialiseActiveListener();
+        err = bitmap->Resize(frameSize);
+        decoder->Convert(&listener->iStatus, *bitmap,i);
+        CActiveScheduler::Start();
+        err = listener->iStatus.Int();
+        if(err != KErrNone)
+            {
+            result = EFail; //fail if couldn't decode all frames.
+            break;
+            }
+        err = bitmap->Resize(TSize(0,0));
+        }
+    CleanupStack::PopAndDestroy(3); //listener, bitmap, decoder
+    return result;
+    }
--- a/imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestStep.h	Sat Feb 20 00:20:15 2010 +0200
+++ b/imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestStep.h	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -2245,4 +2245,23 @@
     CActiveScheduler* iScheduler;
     };
 
+//AKAL-7YHLPR : Crash found in Themes Thread.
+//memory corruption for Gif image secret.gif 
+NONSHARABLE_CLASS(RTestStep_5108): public RICLCodecDefectTestStep
+    {
+public:
+    static RTestStep_5108* NewL(CTestSuite* aSuite);
+    // From RICLCodecDefectTestStep
+    TVerdict OpenL();
+    TVerdict DoTestStepL();
+    void Close();
+        
+private:
+    RTestStep_5108(CTestSuite* aSuite);
+        
+private:
+    RFs iFs;
+    CActiveScheduler* iScheduler;
+    };
+
 #endif // ICLCODECDEFECTTESTSTEP_H
--- a/imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestSuite.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/imagingandcamerafws/imagingunittest/TSU_ICL_COD_03/src/ICLCodecDefectTestSuite.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -127,6 +127,7 @@
 	AddTestStepL(RTestStep_5112::NewL(this));
 	AddTestStepL(RTestStep_5113::NewL(this));
 	AddTestStepL(RTestStep_5114::NewL(this));
+	AddTestStepL(RTestStep_5108::NewL(this));
 	}
 
 void CICLCodecDefectTestSuite::InitSystemPath()
--- a/mdfdevvideoextensions/nga_mdf_postprocessor/inc/NGAPostProcHwDevice.h	Sat Feb 20 00:20:15 2010 +0200
+++ b/mdfdevvideoextensions/nga_mdf_postprocessor/inc/NGAPostProcHwDevice.h	Fri Mar 12 15:50:33 2010 +0200
@@ -1051,7 +1051,6 @@
 	RChunk										iChunk;
 	RSurfaceManager::TInfoBuf 					iInfo;
 	TSurfaceId									iSurfaceId;
-	TSurfaceId									iRedrawSurfaceId;
 	TBool           							iIsInputEnded;
 	CNGAPostProcTimer*							iPostingTimer;
 	CMMFDevVideoPlay::TPictureCounters  		iPictureCounters;
--- a/mdfdevvideoextensions/nga_mdf_postprocessor/src/NGAPostProcHwDevice.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mdfdevvideoextensions/nga_mdf_postprocessor/src/NGAPostProcHwDevice.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -55,27 +55,27 @@
 
 CMMFVideoPostProcHwDevice* CNGAPostProcHwDevice::NewL() 
 { 
-   PP_DEBUG(_L("CNGAPostProcHwDevice:NewL() ++"));
+   PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() ++"));
 
     CNGAPostProcHwDevice* self = new (ELeave) CNGAPostProcHwDevice; 
     CleanupStack::PushL(self);
     self->ConstructL(); 
     CleanupStack::Pop();
 
-   PP_DEBUG(_L("CNGAPostProcHwDevice:NewL() --"));
+   PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() --"));
     return (CMMFVideoPostProcHwDevice*)self; 
 }
 
 void CNGAPostProcHwDevice::ConstructL() 
 { 
-   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ConstructL() ++"), this);
+   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() ++"), this);
     
     // support for VBM buffer interface
     iVBMBufferOptions.iNumInputBuffers  = KMaxVBMBuffers; 
     iVBMBufferOptions.iBufferSize = TSize(KMaxVBMInputWidth, KMaxVBMInputHeight);
     iPostingTimer = CNGAPostProcTimer::NewL(*this);
     iWsSession.Connect();
-   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ConstructL() --"), this);
+   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() --"), this);
 }
 
 CNGAPostProcHwDevice::CNGAPostProcHwDevice() 
@@ -106,14 +106,13 @@
             iKeyFrameMode(EFalse),
             iFPObserver(NULL)
 {
-	iRedrawSurfaceId = TSurfaceId::CreateNullId();
 	iSurfaceId 		 = TSurfaceId::CreateNullId();
 	iAttributes().iPixelFormat    = EUidPixelFormatYUV_422Interleaved;
 }
 
 CNGAPostProcHwDevice::~CNGAPostProcHwDevice()
 {
-   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:~() ++"), this);
+   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::~CNGAPostProcHwDevice() ++"), this);
    	if (iSessionManager)
     {
         iSessionManager->CancelUpdate();
@@ -655,7 +654,7 @@
 
 void CNGAPostProcHwDevice::MmavsoSetAllowedOutputL(TUint aAllowedOutputMask)
 {
-   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL aAllowedOutputMask=%d ++"), this,aAllowedOutputMask);  
+   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL aAllowedOutputMask=0x%08x ++"), this,aAllowedOutputMask);  
    TInt err = KErrNone;
    iSurfaceMask = surfaceHints::EAllowInternalOnly;
     if (aAllowedOutputMask == EVideoAllowAll)
@@ -816,6 +815,14 @@
 	TInt err = KErrNone;
 	if(iResourceLost)
 	{
+        err = AddHints();
+        if (err != KErrNone)
+        {
+            PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost -- failed to AddHints %d"), 
+                         this, err);
+            iProxy->MdvppFatalError(this, err);	
+            return;   
+        }
 		err = RegisterSurface(iSurfaceId);
 		if (err != KErrNone)
 		{
@@ -826,19 +833,12 @@
 			iProxy->MdvppFatalError(this, err);	
 			return;   				
 		}
-        err = AddHints();
-        if (err != KErrNone)
-		{
-		   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost -- failed to AddHints %d"), 
-		   				this, err);
-			iProxy->MdvppFatalError(this, err);	
-			return;   				
-		}
-		iSessionManager->PostPicture(iSurfaceId, 0, 1, EFalse);
-	   	PublishSurfaceCreated();
-	   	iResourceLost = EFalse;
-	}
-	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw --"), this);
+
+        iSessionManager->PostPicture(iSurfaceId, 0, 1, EFalse);
+        PublishSurfaceCreated();
+        iResourceLost = EFalse;
+    }
+    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw --"), this);
 }
 
 void CNGAPostProcHwDevice::Start() 
@@ -1274,16 +1274,11 @@
 void CNGAPostProcHwDevice::MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId)
 {
 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL()++"), this);
-	if(iSurfaceId == aSurfaceId && !aSurfaceId.IsNull())
+	if(!aSurfaceId.IsNull())
 	{
-		if(iInfo().iBuffers > 1) // No need to return temprory redraw surface buffer to decoder
-		{
-			ReleaseProcessQ();
-		}
 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL(): UnregisterSurface ID = 0x%x"), this, aSurfaceId );
-		iWsSession.UnregisterSurface(0, iSurfaceId);
-		iSurfaceHandler->DestroySurface(iSurfaceId);
-		iSurfaceId = TSurfaceId::CreateNullId();
+		iWsSession.UnregisterSurface(0, aSurfaceId);
+		iSurfaceHandler->DestroySurface(aSurfaceId);
 	}
 		
 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL() --"), this);
@@ -1318,21 +1313,12 @@
 void CNGAPostProcHwDevice::MmvroResourcesLost(TUid )
 {
     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ++"), this);
-    if(!iRedrawSurfaceId.IsNull())
-	{
-		iResourceLost = ETrue;
-		Pause();
-		ReleaseInputQ();
-		iSessionManager->CancelUpdate();
-		ReleaseProcessQ();
-		iWsSession.UnregisterSurface(0, iRedrawSurfaceId);
-		iSurfaceHandler->DestroySurface(iRedrawSurfaceId);
-		iRedrawSurfaceId = TSurfaceId::CreateNullId();
-	}
-	else
-	{
-		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvroResourcesLost ERROR iRedrawSurfaceId NULL"), this);
-	}
+	iResourceLost = ETrue;
+	Pause();
+	ReleaseInputQ();
+	iSessionManager->CancelUpdate();
+	ReleaseProcessQ();
+	iVideoSurfaceObserver->MmvsoRemoveSurface();
     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost --"), this);
 }
 
@@ -1382,8 +1368,6 @@
    	TInt err = KErrNone;
 	SetSurfaceAttributes(surfaceSize, 1); 
 	
-	iRedrawSurfaceId = iSurfaceId;
-	
   	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
   	if (err != KErrNone)
 	{
@@ -1438,8 +1422,7 @@
     if(!iSurfaceId.IsNull())
     {
     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface Cleaning ReDraw Surface"), this);
-	    iWsSession.UnregisterSurface(0, iSurfaceId);
-		iSurfaceHandler->DestroySurface(iSurfaceId);
+		iVideoSurfaceObserver->MmvsoRemoveSurface();
 	}
     
     iSurfaceId            = aSurfaceID;
@@ -1464,6 +1447,13 @@
 	   				this, err);
 	    return err;
 	}
+    err = AddHints();
+    if (err != KErrNone)
+    {
+        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to AddHints %d"), 
+                    this, err);
+        return err;
+    }
 	err = RegisterSurface(iSurfaceId);
 	if (err != KErrNone)
 	{
@@ -1473,21 +1463,15 @@
 	   	iSurfaceId = TSurfaceId::CreateNullId();
 	    return err;
 	}
-	err = AddHints();
-	if (err != KErrNone)
-	{
-	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to AddHints %d"), 
-	   				this, err);
-	    return err;
-	}
-	err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
-	if (err != KErrNone)
-	{
-	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to get Surface info %d"), 
-	   				this, err);
-	    return err;
-	}		
-	  
+
+    err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
+    if (err != KErrNone)
+    {
+        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to get Surface info %d"), 
+                     this, err);
+        return err;
+    }
+ 
   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface err=%d"), this, err);
    return err;
 }
@@ -1790,20 +1774,21 @@
 	   		iSurfaceId = TSurfaceId::CreateNullId();
     	    return err;
     	}
-    	err = RegisterSurface(iSurfaceId);
-    	if (err != KErrNone)
-    	{
-    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to RegisterSurface %d"), this, err);
-    	   	iSurfaceHandler->DestroySurface(iSurfaceId);
-	   		iSurfaceId = TSurfaceId::CreateNullId();
-    	    return err;
-    	}
-   	    err = AddHints();
-   	    if (err != KErrNone)
-    	{
-    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to AddHints %d"), this, err);
-    	    return err;
-    	}
+        err = AddHints();
+        if (err != KErrNone)
+        {
+            PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to AddHints %d"), this, err);
+            return err;
+        }
+        err = RegisterSurface(iSurfaceId);
+        if (err != KErrNone)
+        {
+            PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to RegisterSurface %d"), this, err);
+            iSurfaceHandler->DestroySurface(iSurfaceId);
+            iSurfaceId = TSurfaceId::CreateNullId();
+            return err;
+        }
+
     }
     return err;
 } 
@@ -2087,7 +2072,7 @@
 
 TInt CNGAPostProcHwDevice::AddHints()
 {
-   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints ++"), this);
+   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints iSurfaceMask 0x%08x ++"), this, iSurfaceMask);
    TInt err = KErrNone;
    iHint.Set(iSurfaceKey,iSurfaceMask,ETrue);
    err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
--- a/mmlibs/mmfw/MMPFiles/client/MediaClientVideo.mmp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/MMPFiles/client/MediaClientVideo.mmp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -41,6 +41,7 @@
 source			mmfclientvideoplayer2.cpp
 source			mediaclientvideodisplaybody.cpp
 source			mediaclientextdisplayinterface.cpp
+source			mediaclientextdisplayhandler.cpp
 #endif 
 
 source			mmfclientvideoplayerbody.cpp
@@ -89,7 +90,7 @@
 	baseaddress	0x4F2A0000
 end
 
-// MACRO __ENABLE_MEDIA_CLIENT_VIDEO_TRACE__
+MACRO __ENABLE_MEDIA_CLIENT_VIDEO_TRACE__
 
 
                     
--- a/mmlibs/mmfw/MMPFiles/client/mediaclientvideodisplay.mmp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/MMPFiles/client/mediaclientvideodisplay.mmp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -36,6 +36,7 @@
 source			mediaclientvideodisplay.cpp 
 source			mediaclientvideodisplaybody.cpp
 source			mediaclientextdisplayinterface.cpp 
+source			mediaclientextdisplayhandler.cpp
 
 library			ws32.lib
 library			euser.lib
@@ -45,7 +46,7 @@
 
 nostrictdef
 
-// MACRO __ENABLE_MEDIA_CLIENT_VIDEO_TRACE__
+MACRO __ENABLE_MEDIA_CLIENT_VIDEO_TRACE__
 
 SMPSAFE
 
--- a/mmlibs/mmfw/inc/mmf/PLUGIN/mmfmediaclientextdisplayinterface.h	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/inc/mmf/PLUGIN/mmfmediaclientextdisplayinterface.h	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -22,23 +22,23 @@
 #define MMFMEDIACLIENTEXTDISPLAYINTERFACE_H_
 
 #include <e32base.h>
-#include <graphics/surface.h>
+
+#define MMF_MEDIA_CLIENT_EXT_DISPLAY_INTERFACE_V2
 
 /**
 
-Mixin class capable of handling events and requests from provider
+Mixin class capable of handling events from provider
 
 */
 class MExtDisplayConnectionProviderCallback
     {
 public:
-    virtual void MedcpcExtDisplayCalculateExtentAndViewportL(TRect& aExtent, TRect& aViewport, TRect& aExternalDisplayRect) = 0;
     virtual void MedcpcExtDisplayNotifyConnected(TBool aExtDisplayConnected) = 0;
     };
 
 /**
 
-Base class for external display connection provider plugins.
+Mixin class for external display connection provider plugins.
 
 */
 class CExtDisplayConnectionProviderInterface : public CBase
@@ -46,70 +46,56 @@
 public:
 
     /**
-    Determines if external displays are supported by checking if any implementations for
-    supporting external displays are available.
+    Allocates and constructs a new provider plugin.
 
-    @return ETrue if supported otherwise EFalse
+    Uses ECOM to instantiate a new provider plugin. Can leave with any of the system-wide error codes.
+
+    @leave  KErrNotSupported There is no support for external displays.
+    @return A pointer to the new provider plugin.
 
     */
-    static TBool ExternalDisplaySupportedL();
-    
-	/**
-	Allocates and constructs a new provider plugin.
-
-	Uses ECOM to instantiate a new provider plugin. Can leave with any of the system-wide error codes.
+    static CExtDisplayConnectionProviderInterface* NewL();
 
-	@param  aCallback
-	        A reference to an object that can be used by the provider to send
-            events back to the client and make request on the client.
-	@param  aSurfaceId
-	        The surfaceId. 
-    @leave  KErrNotSupported There is no support for external displays.
-	@return A pointer to the new provider plugin.
-
-	*/
-	static CExtDisplayConnectionProviderInterface* NewL(MExtDisplayConnectionProviderCallback& aCallback, TSurfaceId& aSurfaceId);
-
+    /**
+    Function to be implemented by connection provider that allows the callback to be set.
+    
+    @param  aCallback
+        A reference to an object that can be used by the provider to send events back to the client.
+    */
+    virtual void SetExtDisplayConnectionProviderCallback(MExtDisplayConnectionProviderCallback& aCallback) = 0;
+	    
     /**
     Function to be implemented by connection provider that indicates whether an external display is
     connected.
     
-    @return ETrue if external display is connectde otherwise EFalse.
+    @return ETrue if external display is connected otherwise EFalse.
     */
-	virtual TBool ExtDisplayConnectedL() = 0;
-	    
-	/**
-	Default destructor.
-	*/
-	IMPORT_C virtual ~CExtDisplayConnectionProviderInterface();
-	
-protected:
-	/**
-	Constructor.
-	*/
-    IMPORT_C CExtDisplayConnectionProviderInterface();
-	
+	virtual TBool ExtDisplayConnected() = 0;
+
+    /**
+    Function to be implemented by connection provider that indicates the display id that should
+    be used for the external display port.
+    
+    @return TInt the display id for the external display port
+    */
+    virtual TInt ExtDisplayId() = 0;
+
     /**
-     The callback handler for the provider plugin.
-     */
-     MExtDisplayConnectionProviderCallback* iCallback; // not owned
+    Default destructor.
+    */
+    IMPORT_C virtual ~CExtDisplayConnectionProviderInterface();
 
-     /**
-     The surface Id.
-     */
-     TSurfaceId iSurfaceId; // not owned
-     
+protected:
+    /**
+    Constructor.
+    */
+    IMPORT_C CExtDisplayConnectionProviderInterface();
+    
 private:
-	/**
-	This is internal and not intended for use.
-	*/
-	void ConstructL(MExtDisplayConnectionProviderCallback& aCallback, TSurfaceId& aSurfaceId);
-	
-private:
-	/**
-	Required by ECOM.
-	*/
-	TUid iInstanceKey;
+    /**
+    Required by ECOM.
+    */
+    TUid iInstanceKey;
 	};
 
 #endif /* MMFMEDIACLIENTEXTDISPLAYINTERFACE_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mmlibs/mmfw/src/Client/Video/mediaclientextdisplayhandler.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -0,0 +1,96 @@
+// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+//
+
+#include "mediaclientextdisplayhandler.h"
+#include "mediaclientvideotrace.h"
+
+CMediaClientExtDisplayHandler* CMediaClientExtDisplayHandler::NewL(TInt aDisplayId)
+    {
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::NewL +++");
+    CMediaClientExtDisplayHandler* self = new (ELeave) CMediaClientExtDisplayHandler(aDisplayId);
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::NewL ---");
+    return self;
+    }
+
+CMediaClientExtDisplayHandler::CMediaClientExtDisplayHandler(TInt aDisplayId)
+: iDisplayId(aDisplayId)
+    {   
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::CMediaClientExtDisplayHandler +++"); 
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::CMediaClientExtDisplayHandler ---");
+    }
+
+void CMediaClientExtDisplayHandler::ConstructL()
+    {
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::ConstructL +++");
+    
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::ConstructL RWsSession Connect");
+    TInt err = iWs.Connect();
+    if (err != KErrNone)
+        {
+        DEBUG_PRINTF("CMediaClientExtDisplayHandler::ConstructL Windows Server unavailable");
+        User::Leave(err);
+        }
+
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::ConstructL CWsScreenDevice Create");
+    iScreen = new (ELeave) CWsScreenDevice(iWs);
+    User::LeaveIfError(iScreen->Construct(iDisplayId));
+
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::ConstructL RWindowGroup Create");
+    iRootWindow = RWindowGroup(iWs);
+    User::LeaveIfError(iRootWindow.Construct((TUint32)this, ETrue));
+
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::ConstructL RWindow Create");
+    iExternalDisplayWindow = RWindow(iWs);
+    User::LeaveIfError(iExternalDisplayWindow.Construct(iRootWindow,((TUint32)(this)) + 1));
+    DEBUG_PRINTF2("CMediaClientExtDisplayHandler::ConstructL - iExternalDisplayWindow WsHandle 0x%X", iExternalDisplayWindow.WsHandle());
+
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::ConstructL Setup external window");
+    iExternalDisplayWindow.SetExtent(TPoint(0,0), iScreen->SizeInPixels());
+    iExternalDisplayWindow.SetVisible(ETrue);
+    iExternalDisplayWindow.Activate();
+    iWs.Flush();
+    
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::ConstructL ---");
+    }
+
+CMediaClientExtDisplayHandler::~CMediaClientExtDisplayHandler()
+    {
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::~CMediaClientExtDisplayHandler +++");
+    
+    iExternalDisplayWindow.Close();
+    iRootWindow.Close();
+    delete iScreen;
+    iScreen = NULL;
+    iWs.Close();
+    
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::~CMediaClientExtDisplayHandler ---");
+    }
+
+RWindowBase* CMediaClientExtDisplayHandler::Window()
+    {
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::Window +++");
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::Window ---");
+    return &iExternalDisplayWindow;
+    }
+
+TSize CMediaClientExtDisplayHandler::DisplaySizeInPixels()
+    {
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::DisplaySizeInPixels +++");
+    DEBUG_PRINTF("CMediaClientExtDisplayHandler::DisplaySizeInPixels ---");
+    return iScreen->SizeInPixels();
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mmlibs/mmfw/src/Client/Video/mediaclientextdisplayhandler.h	Fri Mar 12 15:50:33 2010 +0200
@@ -0,0 +1,52 @@
+// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+//
+
+#ifndef MEDIACLIENTVIDEODISPLAYHANDLER_H
+#define MEDIACLIENTVIDEODISPLAYHANDLER_H
+
+#include <w32std.h>
+
+/**
+@internalTechnology
+@released
+
+*/
+NONSHARABLE_CLASS(CMediaClientExtDisplayHandler) : public CBase
+    {
+public:
+
+    static CMediaClientExtDisplayHandler* NewL(TInt aDisplayId);
+    
+    RWindowBase* Window();
+    TSize DisplaySizeInPixels();
+    
+    ~CMediaClientExtDisplayHandler();
+
+private:
+    
+    CMediaClientExtDisplayHandler(TInt aDisplayId);
+    void ConstructL();
+    
+private:
+    
+    TInt iDisplayId;
+    CWsScreenDevice* iScreen;
+    RWindow iExternalDisplayWindow;
+    RWsSession iWs;
+    RWindowGroup iRootWindow;
+    };
+
+#endif // MEDIACLIENTVIDEODISPLAYHANDLER_H
+
--- a/mmlibs/mmfw/src/Client/Video/mediaclientextdisplayinterface.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/src/Client/Video/mediaclientextdisplayinterface.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -18,50 +18,30 @@
 #include <e32cmn.h> 
 #include <ecom/ecom.h>
 
-TBool CExtDisplayConnectionProviderInterface::ExternalDisplaySupportedL()
+void CleanupEComArray(TAny* aArray);
+
+CExtDisplayConnectionProviderInterface* CExtDisplayConnectionProviderInterface::NewL()
     {
     RImplInfoPtrArray implInfoArray;
-    REComSession::ListImplementationsL(TUid::Uid(KMediaDisplayExtProviderInterfaceUid), implInfoArray);
+    TCleanupItem cleanup(CleanupEComArray, &implInfoArray);
+    CleanupStack::PushL(cleanup);
 
-    TBool ret = EFalse;
-    if(implInfoArray.Count() > 0)
-        {
-        ret = ETrue;
-        }
-    
-    implInfoArray.Close();
-    return ret;
-    }
-
-CExtDisplayConnectionProviderInterface* CExtDisplayConnectionProviderInterface::NewL(MExtDisplayConnectionProviderCallback& aCallback, TSurfaceId& aSurfaceId)
-    {
-    RImplInfoPtrArray implInfoArray;
-    CleanupClosePushL(implInfoArray);
     REComSession::ListImplementationsL(TUid::Uid(KMediaDisplayExtProviderInterfaceUid), implInfoArray);
     
     if(implInfoArray.Count() == 0)
         {
-        User::Leave(KErrNotSupported);
+        CleanupStack::PopAndDestroy(); // implInfoArray
+        return NULL;
         }
     
     CExtDisplayConnectionProviderInterface* self = 
         REINTERPRET_CAST(CExtDisplayConnectionProviderInterface*, REComSession::CreateImplementationL(
                 implInfoArray[0]->ImplementationUid(), _FOFF(CExtDisplayConnectionProviderInterface, iInstanceKey)));
-    CleanupStack::PushL(self);
-    
-    self->ConstructL(aCallback, aSurfaceId);
-    CleanupStack::Pop(self);
     
     CleanupStack::PopAndDestroy(); // implInfoArray
     return self;
     }
 
-void CExtDisplayConnectionProviderInterface::ConstructL(MExtDisplayConnectionProviderCallback& aCallback, TSurfaceId& aSurfaceId)
-    {
-    iCallback = &aCallback;
-    iSurfaceId = aSurfaceId;
-    }
-
 EXPORT_C CExtDisplayConnectionProviderInterface::~CExtDisplayConnectionProviderInterface()
     {
     REComSession::DestroyedImplementation(iInstanceKey);
@@ -70,3 +50,10 @@
 EXPORT_C CExtDisplayConnectionProviderInterface::CExtDisplayConnectionProviderInterface()
     {
     }
+
+// CleanupEComArray function is used for cleanup support of locally declared arrays
+void CleanupEComArray(TAny* aArray)
+    {
+    (static_cast<RImplInfoPtrArray*> (aArray))->ResetAndDestroy();
+    (static_cast<RImplInfoPtrArray*> (aArray))->Close();
+    }
--- a/mmlibs/mmfw/src/Client/Video/mediaclientvideodisplay.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/src/Client/Video/mediaclientvideodisplay.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -75,12 +75,12 @@
 
 void CMediaClientVideoDisplay::ConstructL(TInt aDisplayId)
 	{
-	iBody = CMediaClientVideoDisplayBody::NewL(aDisplayId);
+	iBody = CMediaClientVideoDisplayBody::NewL(aDisplayId, ETrue);
 	}
 
 void CMediaClientVideoDisplay::ConstructL(TInt aDisplayId, const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
 	{
-	iBody = CMediaClientVideoDisplayBody::NewL(aDisplayId, aSurfaceId, aCropRect, aAspectRatio);
+	iBody = CMediaClientVideoDisplayBody::NewL(aDisplayId, aSurfaceId, aCropRect, aAspectRatio, ETrue);
 	}
 
 /**
--- a/mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -16,48 +16,62 @@
 #include "mediaclientvideodisplaybody.h"
 #include "mediaclientvideotrace.h"
 #include <surfaceeventhandler.h>
+#include <mmf/plugin/mmfmediaclientextdisplayinterface.hrh>
+#include <e32cmn.h>
+#include <ecom/ecom.h>
 
-CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId)
+CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, TBool aExtDisplaySwitchingControl)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL +++"));
-	CMediaClientVideoDisplayBody* self = new (ELeave) CMediaClientVideoDisplayBody(aDisplayId);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aExtDisplaySwitchingControl %d", aExtDisplaySwitchingControl);
+    
+    CMediaClientVideoDisplayBody* self = new (ELeave) CMediaClientVideoDisplayBody(aDisplayId);
 	CleanupStack::PushL(self);
-	self->ConstructL();
+	self->ConstructL(aExtDisplaySwitchingControl);
 	CleanupStack::Pop(self);
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL ---");
 	return self;
 	}
 
 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId,
-		const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
+		const TRect& aCropRect, TVideoAspectRatio aAspectRatio, TBool aExtDisplaySwitchingControl)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL +++");
+	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aDisplayId %d", aDisplayId);
+    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]);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::NewL - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::NewL - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::NewL - aExtDisplaySwitchingControl %d", aExtDisplaySwitchingControl);
+
 	if(aSurfaceId.IsNull())
 		{
 		User::Leave(KErrArgument);
 		}
 	CMediaClientVideoDisplayBody* self = new(ELeave) CMediaClientVideoDisplayBody(aDisplayId, aSurfaceId, aCropRect, aAspectRatio);
 	CleanupStack::PushL(self);
-	self->ConstructL();
+	self->ConstructL(aExtDisplaySwitchingControl);
 	CleanupStack::Pop();
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::NewL ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::NewL ---");
 	return self;
 	}
 
-void CMediaClientVideoDisplayBody::ConstructL()
+void CMediaClientVideoDisplayBody::ConstructL(TBool aExtDisplaySwitchingControl)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConstructL +++"));
-	
-	iExtDisplaySwitchingSupported = CExtDisplayConnectionProviderInterface::ExternalDisplaySupportedL();
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL +++");
+
+	SetWindowArrayPtr2Client();
+
+	CreateExtDisplayPluginL();
 	
 	// Try and enable display switching by default. If this leaves then do so quietly.
 	// Either the client has no scheduler installed or the device does not support external
 	// switching (i.e. no plugin was found) 
-	TRAPD(err, SetExternalDisplaySwitchingL(ETrue));
+	TRAPD(err, SetExternalDisplaySwitchingL(aExtDisplaySwitchingControl));
 	err = err; // remove compile warning
-	DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::ConstructL SetExternalDisplaySwitchingL returned with %d"), err);
+	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConstructL SetExternalDisplaySwitchingL returned with %d", err);
 	
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConstructL ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConstructL ---");
 	}
 
 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId, const TSurfaceId& aSurfaceId,
@@ -67,33 +81,38 @@
 	iCropRect(aCropRect),
 	iAspectRatio(aAspectRatio)
 	{	
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++");
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---");
 	}
 
 CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody(TInt aDisplayId) :
 	iDisplayId(aDisplayId)
 	{	
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody +++");
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CMediaClientVideoDisplayBody ---");
 	}
 
 CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody()
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody +++");
 
+	// remove for whichever array is current
 	RemoveBackgroundSurface(ETrue);
-		
-	iWindows.Close();	
-	delete iExtDisplayConnectionProvider;
+
+	iClientWindows.Close();	
+    iExtDisplayWindows.Close(); 
+
+	delete iExtDisplayHandler;
+	RemoveExtDisplayPlugin();
 	REComSession::FinalClose();
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody ---"));
+	
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::~CMediaClientVideoDisplayBody ---");
 	}
 
 void CMediaClientVideoDisplayBody::AddDisplayL(MMMFSurfaceEventHandler& aEventHandler)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayL +++"));
-	if (iEventHandler != NULL)
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayL +++");
+	if (iEventHandler)
 		{
 		User::Leave(KErrInUse);
 		}
@@ -104,15 +123,24 @@
 		{
 		iEventHandler->MmsehSurfaceCreated(iDisplayId, iSurfaceId, iCropRect, iAspectRatio);
 		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayL ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayL ---");
 	}
 	
 void CMediaClientVideoDisplayBody::AddDisplayWindowL(const RWindowBase* aWindow, const TRect& aClipRect, const TRect& aCropRegion, const TRect& aVideoExtent, 
 															TReal32 aScaleWidth, TReal32 aScaleHeight, TVideoRotation aRotation, 
 															TAutoScaleType aAutoScaleType, TInt aHorizPos, TInt aVertPos, RWindow* aWindow2)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayWindowL +++"));
-	TInt pos = iWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow->WsHandle());
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aClipRect %d,%d - %d,%d", aClipRect.iTl.iX, aClipRect.iTl.iY, aClipRect.iBr.iX, aClipRect.iBr.iY);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::AddDisplayWindowL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aScaleWidth %f, aScaleHeight %f", aScaleWidth, aScaleHeight);
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aRotation %d", aRotation);
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL - aAutoScaleType %d", aAutoScaleType);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::AddDisplayWindowL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
+
+	TInt pos = iClientWindows.Find(aWindow->WsHandle(), TWindowData::CompareByWsHandle);
 	
 	if (pos != KErrNotFound)
 		{
@@ -120,67 +148,83 @@
 		}
 	
 	TWindowData winData(aWindow, aClipRect, aVideoExtent, aScaleWidth, aScaleHeight, aRotation, aAutoScaleType, aHorizPos, aVertPos, aWindow2);
-	iWindows.AppendL(winData);
+	iClientWindows.AppendL(winData);
 	
 	iCropRegion = aCropRegion;
 	
 	if (IsSurfaceCreated())
 		{
-        if(iExtDisplaySwitchingSupported && iClientRequestedExtDisplaySwitching)
+		// first client window just added
+        if((iClientWindows.Count() == 1) && iClientRequestedExtDisplaySwitching)
             {
-            CreateExtDisplayConnProvAndRemoveSurfaceL(EFalse);
+            if(iExtDisplayConnected)
+                {
+                TRAPD(err, CreateExtDisplayHandlerL());
+                DEBUG_PRINTF2("CMediaClientVideoDisplayBody::AddDisplayWindowL CreateExtDisplayHandlerL error %d", err);
+                if(err == KErrNone)
+                    {
+                    SetWindowArrayPtr2Ext();
+                    User::LeaveIfError(RedrawWindows(aCropRegion));
+                    }
+                }
             }
         
-        if(!iExtDisplayConnected)
+        if(!iExtDisplayConnected || !iExtDisplayHandler)
             {
             User::LeaveIfError(SetBackgroundSurface(winData, aCropRegion));
             }
 		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::AddDisplayWindowL ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::AddDisplayWindowL ---");
 	}
 
 void CMediaClientVideoDisplayBody::RemoveDisplay()
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplay +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplay +++");
 	iEventHandler = NULL;
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplay ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplay ---");
 	}	
 
 TInt CMediaClientVideoDisplayBody::RemoveDisplayWindow(const RWindowBase& aWindow)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++"));
-	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow +++");
+	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
 	
 	if (pos >= 0)
 		{
-		if (IsSurfaceCreated())
+		if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
 			{
-			iWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
-
-			// Make sure all window rendering has completed before proceeding
-			RWsSession* ws = iWindows[pos].iWindow->Session();
-			if (ws)
-				{
-				ws->Finish();
-				}
+			iClientWindows[pos].iWindow->RemoveBackgroundSurface(ETrue);
+            // Make sure all window rendering has completed before proceeding
+            RWsSession* ws = iClientWindows[pos].iWindow->Session();
+            if (ws)
+              {
+              ws->Finish();
+              }
 			}
-		iWindows.Remove(pos);
+		iClientWindows.Remove(pos);
 		
-		if(iWindows.Count() == 0)
+		if(iClientWindows.Count() == 0 && iExtDisplayConnected && iExtDisplayHandler)
 		    {
-		    RemoveExtDisplayConnProv();
+		    RemoveBackgroundSurface(ETrue);
+		    SetWindowArrayPtr2Client();
+		    RemoveExtDisplayHandler();
 		    }
 		}
 	
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveDisplayWindow ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveDisplayWindow ---");
 	return pos;
 	}
 
 
 TInt CMediaClientVideoDisplayBody::SurfaceCreated(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceCreated +++"));
-	TBool emitEvent = EFalse;
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated +++");
+    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]);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
+
+    TBool emitEvent = EFalse;
 	if((iSurfaceId != aSurfaceId) && (!aSurfaceId.IsNull()))
 		{
 		emitEvent = ETrue;
@@ -197,52 +241,54 @@
 		}
 
 	TInt err = KErrNone;
-    if(iExtDisplaySwitchingSupported && iClientRequestedExtDisplaySwitching)
+    if((iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching)
         {
-        TRAP(err, CreateExtDisplayConnProvAndRemoveSurfaceL(EFalse));
+        if(iExtDisplayConnected && !iExtDisplayHandler)
+            {
+            TRAP(err, CreateExtDisplayHandlerL());
+            DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SurfaceCreated CreateExtDisplayHandlerL error %d", err);
+            if(err == KErrNone)
+                {
+                SetWindowArrayPtr2Ext();
+                }
+            }
         }
     
-    if(!iExtDisplayConnected)
-        {
-        err = RedrawWindows(aCropRegion);
-        }
+    err = RedrawWindows(aCropRegion);
     
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceCreated ---"));
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceCreated ---");
 	return err;
 	}
 
 void CMediaClientVideoDisplayBody::RemoveBackgroundSurface(TBool aTriggerRedraw)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveBackgroundSurface +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveBackgroundSurface +++");
 	if (IsSurfaceCreated())
 		{
-		TInt count = iWindows.Count();
+		RWsSession* ws = NULL;
+		TInt count = iWindowsArrayPtr->Count();
 	
-		RWsSession* ws = NULL;
 		for (TInt i = 0; i < count; ++i)
 			{
-			iWindows[i].iWindow->RemoveBackgroundSurface(aTriggerRedraw);
-			// Make sure all window rendering has completed before proceeding
-			ws = iWindows[i].iWindow->Session();
-			if (ws)
-				{
-				ws->Finish();
-				}
+			(*iWindowsArrayPtr)[i].iWindow->RemoveBackgroundSurface(aTriggerRedraw);
+            // Make sure all window rendering has completed before proceeding
+            ws = (*iWindowsArrayPtr)[i].iWindow->Session();
+            if (ws)
+                {
+                ws->Finish();
+                }
 			}
 		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveBackgroundSurface ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveBackgroundSurface ---");
 	}
 
 void CMediaClientVideoDisplayBody::RemoveSurface(TBool aControllerEvent)
     {
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveSurface +++"));
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface +++");
     if (IsSurfaceCreated())
         {
-        if(!iExtDisplayConnected)
-            {
-            RemoveBackgroundSurface(ETrue);
-            }
-        
+        RemoveBackgroundSurface(ETrue);
+
         if (iEventHandler  && aControllerEvent)
             {
             iEventHandler->MmsehRemoveSurface(iSurfaceId);
@@ -250,16 +296,24 @@
 
         iSurfaceId = TSurfaceId::CreateNullId();
 
-        RemoveExtDisplayConnProv();
+        if(iExtDisplayConnected && iExtDisplayHandler)
+            {
+            SetWindowArrayPtr2Client();
+            RemoveExtDisplayHandler();
+            }
         }
     
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveSurface ---"));
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveSurface ---");
     }
 
 TInt CMediaClientVideoDisplayBody::SurfaceParametersChanged(const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceParametersChanged +++"));
-	if (!IsSurfaceCreated())
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged +++");
+    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]);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SurfaceCreated - aCropRect %d,%d - %d,%d", aCropRect.iTl.iX, aCropRect.iTl.iY, aCropRect.iBr.iX, aCropRect.iBr.iY);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SurfaceCreated - aAspectRatio %d/%d", aAspectRatio.iNumerator, aAspectRatio.iDenominator);
+
+    if (!IsSurfaceCreated())
 		{
 		return KErrNotSupported;
 		}
@@ -277,24 +331,26 @@
 		iEventHandler->MmsehSurfaceParametersChanged(iSurfaceId, iCropRect, iAspectRatio);
 		}
 
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SurfaceParametersChanged ---"));
+	RedrawWindows(iCropRegion);
+	
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SurfaceParametersChanged ---");
 	return KErrNone;
 	}
 	
 TInt CMediaClientVideoDisplayBody::RedrawWindows(const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RedrawWindows +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RedrawWindows +++");
 	TInt err = KErrNone;	
 
 	iCropRegion = aCropRegion;
 	
 	if(IsSurfaceCreated())
 		{
-		TInt count = iWindows.Count();
+		TInt count = iWindowsArrayPtr->Count();
 	
 		for (TInt i = 0; i < count; ++i)
 			{
-			err = SetBackgroundSurface(iWindows[i], aCropRegion);
+			err = SetBackgroundSurface((*iWindowsArrayPtr)[i], aCropRegion);
 		
 			if (err != KErrNone)
 				{
@@ -303,60 +359,90 @@
 			}
 		}
 		
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RedrawWindows ---"));
+	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::RedrawWindows --- return with %d", err);
 	return err;
 	}
 
+void CMediaClientVideoDisplayBody::UpdateCropRegionL(const TRect& aCropRegion, TInt aPos)
+    {
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL +++");
+
+    TRect prevCropRegion(iCropRegion);
+    iCropRegion = aCropRegion;
+    
+    if (IsSurfaceCreated())
+        {
+        if(prevCropRegion == aCropRegion)
+            {
+            if(!iExtDisplayConnected || !iExtDisplayHandler)
+                {
+                User::LeaveIfError(SetBackgroundSurface(iClientWindows[aPos], aCropRegion));
+                }
+            }
+        else
+            {
+            User::LeaveIfError(RedrawWindows(aCropRegion));
+            }
+        }
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::UpdateCropRegionL ---");    
+    }
+
 void CMediaClientVideoDisplayBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL +++"));
-	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetAutoScaleL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
+
+    TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
 	User::LeaveIfError(pos);
 	
-	iWindows[pos].iAutoScaleType = aScaleType;
-	iWindows[pos].iHorizPos = aHorizPos;
-	iWindows[pos].iVertPos = aVertPos;
-	iCropRegion = aCropRegion;
+	iClientWindows[pos].iAutoScaleType = aScaleType;
+	iClientWindows[pos].iHorizPos = aHorizPos;
+	iClientWindows[pos].iVertPos = aVertPos;
+
+	UpdateCropRegionL(aCropRegion, pos);
 	
-	if (IsSurfaceCreated() && !iExtDisplayConnected)
-		{
-		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
-		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
 	}
 	
 
 void CMediaClientVideoDisplayBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL +++"));
-	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
+
+    TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
 	User::LeaveIfError(pos);
 	
-	iWindows[pos].iRotation = aRotation;
-	iCropRegion = aCropRegion;
-	
-    if (IsSurfaceCreated() && !iExtDisplayConnected)
-		{
-		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
-		}
-	
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL ---"));
+	iClientWindows[pos].iRotation = aRotation;
+
+    UpdateCropRegionL(aCropRegion, pos);
+
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
 	}
 
 TVideoRotation CMediaClientVideoDisplayBody::RotationL(const RWindowBase& aWindow)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RotationL +++"));
-	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RotationL +++");
+	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
 	User::LeaveIfError(pos);
 	
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RotationL ---"));
-	return iWindows[pos].iRotation;
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::RotationL ---");
+	return iClientWindows[pos].iRotation;
 	}
 
 void CMediaClientVideoDisplayBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL +++"));
-	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetScaleFactorL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetScaleFactorL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
+
+    TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
 	User::LeaveIfError(pos);
 	
 	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
@@ -364,137 +450,171 @@
 		User::Leave(KErrArgument);
 		}
 
-	
-	iWindows[pos].iScaleWidth = aWidthPercentage;
-	iWindows[pos].iScaleHeight = aHeightPercentage;
-	iWindows[pos].iAutoScaleType = EAutoScaleNone;
-	iCropRegion = aCropRegion;
+	iClientWindows[pos].iScaleWidth = aWidthPercentage;
+	iClientWindows[pos].iScaleHeight = aHeightPercentage;
+	iClientWindows[pos].iAutoScaleType = EAutoScaleNone;
 	
-    if (IsSurfaceCreated() && !iExtDisplayConnected)
-		{
-		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
-		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL ---"));
+    UpdateCropRegionL(aCropRegion, pos);
+	
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
 	}
 	
 void CMediaClientVideoDisplayBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::GetScaleFactorL +++"));
-	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::GetScaleFactorL +++");
+	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
 	User::LeaveIfError(pos);
 	
-	aWidthPercentage = iWindows[pos].iScaleWidth;
-	aHeightPercentage = iWindows[pos].iScaleHeight;
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::GetScaleFactorL ---"));
+	aWidthPercentage = iClientWindows[pos].iScaleWidth;
+	aHeightPercentage = iClientWindows[pos].iScaleHeight;
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::GetScaleFactorL ---");
 	}
 
 void CMediaClientVideoDisplayBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetAutoScaleL - aScaleType %d", aScaleType);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetAutoScaleL - aHorizPos %d, aVertPos %d", aHorizPos, aVertPos);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetAutoScaleL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
 	
+    TRect prevCropRegion(iCropRegion);
 	iCropRegion = aCropRegion;
-	TInt count = iWindows.Count();
+	TInt count = iClientWindows.Count();
 	
 	for (TInt i = 0; i < count; ++i)
 		{
-		iWindows[i].iAutoScaleType = aScaleType;
-		iWindows[i].iHorizPos = aHorizPos;
-		iWindows[i].iVertPos = aVertPos;
-	    if (IsSurfaceCreated() && !iExtDisplayConnected)
+		iClientWindows[i].iAutoScaleType = aScaleType;
+		iClientWindows[i].iHorizPos = aHorizPos;
+		iClientWindows[i].iVertPos = aVertPos;
+	    if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
 			{
-			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
+			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
 			}
 		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetAutoScaleL ---"));
+	
+	if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
+        {
+        User::LeaveIfError(RedrawWindows(aCropRegion));
+        }
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetAutoScaleL ---");
 	}
 
 
 void CMediaClientVideoDisplayBody::SetRotationL(TVideoRotation aRotation, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL +++"));
-	iCropRegion = aCropRegion;
-	TInt count = iWindows.Count();
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetRotationL - aRotation %d", aRotation);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetRotationL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
+
+    TRect prevCropRegion(iCropRegion);
+    iCropRegion = aCropRegion;
+	TInt count = iClientWindows.Count();
 	
 	for (TInt i = 0; i < count; ++i)
 		{
-		iWindows[i].iRotation = aRotation;
-	    if (IsSurfaceCreated() && !iExtDisplayConnected)
+		iClientWindows[i].iRotation = aRotation;
+        if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
 			{
-			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
+			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
 			}
 		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetRotationL ---"));
+	
+    if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
+        {
+        User::LeaveIfError(RedrawWindows(aCropRegion));
+        }
+	   
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetRotationL ---");
 	}
 		
 void CMediaClientVideoDisplayBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL +++"));
-	if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL +++");
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetScaleFactorL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
+
+    if (aWidthPercentage <= 0.0 || aHeightPercentage <= 0.0)
 		{
 		User::Leave(KErrArgument);
 		}
 	
+    TRect prevCropRegion(iCropRegion);
 	iCropRegion = aCropRegion;
-	TInt count = iWindows.Count();
+	TInt count = iClientWindows.Count();
 	
 	for (TInt i = 0; i < count; ++i)
 		{
-		iWindows[i].iScaleWidth = aWidthPercentage;
-		iWindows[i].iScaleHeight = aHeightPercentage;
-		iWindows[i].iAutoScaleType = EAutoScaleNone;
-	    if (IsSurfaceCreated() && !iExtDisplayConnected)
+		iClientWindows[i].iScaleWidth = aWidthPercentage;
+		iClientWindows[i].iScaleHeight = aHeightPercentage;
+		iClientWindows[i].iAutoScaleType = EAutoScaleNone;
+        if (IsSurfaceCreated() && (!iExtDisplayConnected || !iExtDisplayHandler))
 			{
-			User::LeaveIfError(SetBackgroundSurface(iWindows[i], aCropRegion));
+			User::LeaveIfError(SetBackgroundSurface(iClientWindows[i], aCropRegion));
 			}
 		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetScaleFactorL ---"));
+	
+    if (IsSurfaceCreated() && iExtDisplayConnected && iExtDisplayHandler && (aCropRegion != prevCropRegion))
+        {
+        User::LeaveIfError(RedrawWindows(aCropRegion));
+        }
+	   
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetScaleFactorL ---");
 	}
 
 void CMediaClientVideoDisplayBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetWindowClipRectL +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetWindowClipRectL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetWindowClipRectL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetWindowClipRectL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
 	
-	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
+	TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
 	User::LeaveIfError(pos);
 	
-	iWindows[pos].iClipRect = aWindowClipRect;
-	iCropRegion = aCropRegion;
-	
-    if (IsSurfaceCreated() && !iExtDisplayConnected)
-		{
-		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
-		}
-	
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetWindowClipRectL ---"));
+	iClientWindows[pos].iClipRect = aWindowClipRect;
+
+    UpdateCropRegionL(aCropRegion, pos);
+
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowClipRectL ---");
 	}
 	
 void CMediaClientVideoDisplayBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent, const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetVideoExtentL +++"));
-	TInt pos = iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetVideoExtentL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetVideoExtentL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetVideoExtentL - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
+
+    TInt pos = iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle);
 	User::LeaveIfError(pos);
 	
-	iWindows[pos].iVideoExtent = aVideoExtent;
-	iCropRegion = aCropRegion;
-	
-    if (IsSurfaceCreated() && !iExtDisplayConnected)
-		{
-		User::LeaveIfError(SetBackgroundSurface(iWindows[pos], aCropRegion));
-		}
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetVideoExtentL ---"));
+	iClientWindows[pos].iVideoExtent = aVideoExtent;
+
+    UpdateCropRegionL(aCropRegion, pos);
+    
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetVideoExtentL ---");
 	}
 	
 TBool CMediaClientVideoDisplayBody::HasWindows() const
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::HasWindows +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::HasWindows ---"));
-	return (iWindows.Count() > 0);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::HasWindows +++");
+	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::HasWindows --- return %d", (iClientWindows.Count() > 0));
+	return (iClientWindows.Count() > 0);
 	}
 	
 TInt CMediaClientVideoDisplayBody::SetBackgroundSurface(TWindowData& aWindowData,  
 									const TRect& aCropRegion)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetBackgroundSurface +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetBackgroundSurface +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iWindow WsHandle 0x%X", aWindowData.iWindow->WsHandle());
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - iWindow abs pos %d,%d - width %d, height %d", aWindowData.iWindow->AbsPosition().iX, aWindowData.iWindow->AbsPosition().iY, aWindowData.iWindow->Size().iWidth, aWindowData.iWindow->Size().iHeight);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - iClipRect %d,%d - %d,%d", aWindowData.iClipRect.iTl.iX, aWindowData.iClipRect.iTl.iY, aWindowData.iClipRect.iBr.iX, aWindowData.iClipRect.iBr.iY);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - iVideoExtent %d,%d - %d,%d", aWindowData.iVideoExtent.iTl.iX, aWindowData.iVideoExtent.iTl.iY, aWindowData.iVideoExtent.iBr.iX, aWindowData.iVideoExtent.iBr.iY);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - iScaleWidth %f, iScaleHeight %f", aWindowData.iScaleWidth, aWindowData.iScaleHeight);
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iRotation %d", aWindowData.iRotation);
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface - iAutoScaleType %d", aWindowData.iAutoScaleType);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - iHorizPos %d, iVertPos %d", aWindowData.iHorizPos, aWindowData.iVertPos);
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - aCropRegion %d,%d - %d,%d", aCropRegion.iTl.iX, aCropRegion.iTl.iY, aCropRegion.iBr.iX, aCropRegion.iBr.iY);
 	
 	// required as this private function is called directly from external friend class
 	iCropRegion = aCropRegion;
@@ -509,39 +629,11 @@
     // Viewport is 0 size, don't show any video
     if (viewport.Width() <= 0 || viewport.Height() <= 0)
         {
+        DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- Returned with error %d", KErrArgument);
         return KErrArgument;
         }
 
-	TRect extent;
-	CalculateExtentAndViewport(aWindowData, extent, viewport);
-	
-	aWindowData.iSurfaceConfig.SetViewport(viewport);
-	aWindowData.iSurfaceConfig.SetExtent(extent);
-	aWindowData.iSurfaceConfig.SetOrientation(ConvertRotation(aWindowData.iRotation));
-	
-	aWindowData.iSurfaceConfig.SetSurfaceId(iSurfaceId);
-	
-	// Get the rectangle that bounds the crop rectangle and the viewport.  This should be
-	// the same as the crop rectangle as long as the viewport does not go outside this area.
-	TRect rect(iCropRect);
-	rect.BoundingRect(viewport);
-	TInt err = KErrNone;
-	
-	// Check if the viewport and extent can be displayed as a background surface. The viewport 
-	// is valid if it is within the crop rectangle and is not empty.  The extent is valid if 
-	// it is not empty. 
-	if (rect == iCropRect && !viewport.IsEmpty() && !extent.IsEmpty())
-		{
-		err = aWindowData.iWindow->SetBackgroundSurface(aWindowData.iSurfaceConfig, ETrue);
-		}
-
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetBackgroundSurface ---"));
-	return err;
-	}
-
-void CMediaClientVideoDisplayBody::CalculateExtentAndViewport(const TWindowData& aWindowData, TRect& aExtent, TRect& aViewport)
-    {
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CalculateExtentAndViewport +++"));
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport1 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
 
     TRect videoExtent(aWindowData.iVideoExtent);
     
@@ -552,14 +644,14 @@
         {
         case EVideoRotationNone:
         case EVideoRotationClockwise180:
-            inputWidth = static_cast<TReal32>(aViewport.Width());
-            inputHeight = static_cast<TReal32>(aViewport.Height());
+            inputWidth = static_cast<TReal32>(viewport.Width());
+            inputHeight = static_cast<TReal32>(viewport.Height());
             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iNumerator) / iAspectRatio.iDenominator;
             break;
         case EVideoRotationClockwise90:
         case EVideoRotationClockwise270:
-            inputWidth = static_cast<TReal32>(aViewport.Height());
-            inputHeight = static_cast<TReal32>(aViewport.Width());
+            inputWidth = static_cast<TReal32>(viewport.Height());
+            inputHeight = static_cast<TReal32>(viewport.Width());
             pixelAspectRatio = static_cast<TReal32>(iAspectRatio.iDenominator) / iAspectRatio.iNumerator;
             break;
         default:
@@ -567,14 +659,17 @@
             User::Invariant();
             break;
         }
-        
+    
     TReal32 viewportAspect = pixelAspectRatio * inputWidth / inputHeight;
     TReal32 vidextAspect = static_cast<TReal32>(videoExtent.Width()) / static_cast<TReal32>(videoExtent.Height());
     
+    DEBUG_PRINTF4("CMediaClientVideoDisplayBody::SetBackgroundSurface - inputWidth %f, inputHeight %f, PAR %f", inputWidth, inputHeight, pixelAspectRatio);
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewportAspect %f, vidextAspect %f", viewportAspect, vidextAspect);
+
     // Set the extent to the display area in the window.  The final height and with is to 
     // be changed by deltaHeight and deltaWidth respectively.
-    aExtent = videoExtent;
-    
+    TRect extent(videoExtent);
+
     TInt deltaHeight = 0;
     TInt deltaWidth = 0;
     
@@ -583,12 +678,12 @@
         if (viewportAspect > vidextAspect)
             {
             // Shrink height to get the correct aspect ratio
-            deltaHeight = (TInt) (aExtent.Width() / viewportAspect - aExtent.Height());
+            deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
             }
         else
             {
             // Shrink width to get the correct aspect ratio
-            deltaWidth = (TInt) (aExtent.Height() * viewportAspect - aExtent.Width());
+            deltaWidth = (TInt) (extent.Height() * viewportAspect - extent.Width());
             }
         }
     else if (aWindowData.iAutoScaleType == EAutoScaleClip)
@@ -596,12 +691,12 @@
         if (viewportAspect > vidextAspect)
             {
             // Expand width to get the correct aspect ratio
-            deltaWidth = (TInt) (aExtent.Height() * viewportAspect - aExtent.Width());
+            deltaWidth = (TInt) (extent.Height() * viewportAspect - extent.Width());
             }
         else
             {
             // Expand height to get the correct aspect ratio
-            deltaHeight = (TInt) (aExtent.Width() / viewportAspect - aExtent.Height());
+            deltaHeight = (TInt) (extent.Width() / viewportAspect - extent.Height());
             }
         }
     else if (aWindowData.iAutoScaleType == EAutoScaleStretch)
@@ -624,23 +719,25 @@
         deltaWidth = (TInt) (inputWidth * aWindowData.iScaleWidth * 0.01 - videoExtent.Width());
         }
     
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - deltaWidth %d, deltaHeight %d", deltaWidth, deltaHeight);
+
     // Change the width of the extent in the proper directions and propertions.
     switch (aWindowData.iHorizPos)
         {
     case EHorizontalAlignCenter:
-        aExtent.iTl.iX -= deltaWidth / 2;
-        aExtent.iBr.iX += deltaWidth / 2;
+        extent.iTl.iX -= deltaWidth / 2;
+        extent.iBr.iX += deltaWidth / 2;
         break;
     case EHorizontalAlignLeft:
-        aExtent.iBr.iX += deltaWidth;
+        extent.iBr.iX += deltaWidth;
         break;
     case EHorizontalAlignRight:
-        aExtent.iTl.iX -= deltaWidth;
+        extent.iTl.iX -= deltaWidth;
         break;
     default:
-        TInt width = aExtent.Width() + deltaWidth;
-        aExtent.iTl.iX += aWindowData.iHorizPos;
-        aExtent.iBr.iX = aExtent.iTl.iX + width;
+        TInt width = extent.Width() + deltaWidth;
+        extent.iTl.iX += aWindowData.iHorizPos;
+        extent.iBr.iX = extent.iTl.iX + width;
         break;
         }
     
@@ -648,22 +745,24 @@
     switch (aWindowData.iVertPos)
         {
     case EVerticalAlignCenter:
-        aExtent.iTl.iY -= deltaHeight / 2;
-        aExtent.iBr.iY += deltaHeight / 2;
+        extent.iTl.iY -= deltaHeight / 2;
+        extent.iBr.iY += deltaHeight / 2;
         break;
     case EVerticalAlignTop:
-        aExtent.iBr.iY += deltaHeight;
+        extent.iBr.iY += deltaHeight;
         break;
     case EVerticalAlignBottom:
-        aExtent.iTl.iY -= deltaHeight;
+        extent.iTl.iY -= deltaHeight;
         break;
     default:
-        TInt height = aExtent.Height() + deltaHeight;
-        aExtent.iTl.iY += aWindowData.iVertPos;
-        aExtent.iBr.iY = aExtent.iTl.iY + height;
+        TInt height = extent.Height() + deltaHeight;
+        extent.iTl.iY += aWindowData.iVertPos;
+        extent.iBr.iY = extent.iTl.iY + height;
         break;
         }
         
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - extent1 %d,%d - %d,%d", extent.iTl.iX, extent.iTl.iY, extent.iBr.iX, extent.iBr.iY);
+
     // The video should not be displayed outside the intended video extent or clipping rectangle.  
     // The extent already has the correct size and position for displaying the entire viewport.  
     // The viewport is clipped such that the video is not moved/distorted when we take the extent 
@@ -672,137 +771,180 @@
     TRect viewableArea(videoExtent);
     viewableArea.Intersection(aWindowData.iClipRect);
     
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewableArea %d,%d - %d,%d", viewableArea.iTl.iX, viewableArea.iTl.iY, viewableArea.iBr.iX, viewableArea.iBr.iY);
+
     // Number of pixels (in window coordinates) to be clipped on the right, bottom, top and left sides of
     // the video.
-    TInt dr = Max(0, aExtent.iBr.iX - viewableArea.iBr.iX);
-    TInt db = Max(0, aExtent.iBr.iY - viewableArea.iBr.iY);
-    TInt dt = Max(0, viewableArea.iTl.iY - aExtent.iTl.iY);
-    TInt dl = Max(0, viewableArea.iTl.iX - aExtent.iTl.iX);
+    TInt dr = Max(0, extent.iBr.iX - viewableArea.iBr.iX);
+    TInt db = Max(0, extent.iBr.iY - viewableArea.iBr.iY);
+    TInt dt = Max(0, viewableArea.iTl.iY - extent.iTl.iY);
+    TInt dl = Max(0, viewableArea.iTl.iX - extent.iTl.iX);
     
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - dr %d, db %d, dt %d, dl %d", dr, db, dt, dl);
+
     // Calculate the number of pixels in the video per window pixel in both x and y directions.
     TReal32 wRatio = 0.0f; 
     TReal32 hRatio = 0.0f;
-    
+
     // Make sure we don't divide by 0
-    if (aExtent.Width() != 0)
+    if (extent.Width() != 0)
         {
-        wRatio = inputWidth / static_cast<TReal32>(aExtent.Width());
+        wRatio = inputWidth / static_cast<TReal32>(extent.Width());
         }
     
-    if (aExtent.Height() != 0)
+    if (extent.Height() != 0)
         {
-        hRatio = inputHeight / static_cast<TReal32>(aExtent.Height());
+        hRatio = inputHeight / static_cast<TReal32>(extent.Height());
         }
     
+    DEBUG_PRINTF3("CMediaClientVideoDisplayBody::SetBackgroundSurface - wRatio %f, hRatio %f", wRatio, hRatio);
+
     // Clip the viewport 
     switch (aWindowData.iRotation)
+    {
+    case EVideoRotationNone:
+        viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dr));
+        viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(db));
+        viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dl));
+        viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dt));
+        break;
+    case EVideoRotationClockwise180:
+        viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dl));
+        viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dt));
+        viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dr));
+        viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(db));
+        break;
+    case EVideoRotationClockwise90:
+        viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(db));
+        viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dl));
+        viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dt));
+        viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dr));
+        break;
+    case EVideoRotationClockwise270:
+        viewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dt));
+        viewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dr));
+        viewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(db));
+        viewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dl));
+        break;
+    default:
+        // Should never get to default unless there's been some programming error.
+        User::Invariant();
+        break;
+    }
+    
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - viewport2 %d,%d - %d,%d", viewport.iTl.iX, viewport.iTl.iY, viewport.iBr.iX, viewport.iBr.iY);
+
+    // Clip the extent.
+    extent.Intersection(viewableArea);
+    
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - extent2 %d,%d - %d,%d", extent.iTl.iX, extent.iTl.iY, extent.iBr.iX, extent.iBr.iY);
+
+    aWindowData.iSurfaceConfig.SetViewport(viewport);
+    aWindowData.iSurfaceConfig.SetExtent(extent);
+    aWindowData.iSurfaceConfig.SetOrientation(ConvertRotation(aWindowData.iRotation));
+    
+    aWindowData.iSurfaceConfig.SetSurfaceId(iSurfaceId);
+    
+    // Get the rectangle that bounds the crop rectangle and the viewport.  This should be
+    // the same as the crop rectangle as long as the viewport does not go outside this area.
+    TRect rect(iCropRect);
+    rect.BoundingRect(viewport);
+    TInt err = KErrNone;
+    
+    DEBUG_PRINTF5("CMediaClientVideoDisplayBody::SetBackgroundSurface - rect %d,%d - %d,%d", rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
+
+    // Check if the viewport and extent can be displayed as a background surface. The viewport 
+    // is valid if it is within the crop rectangle and is not empty.  The extent is valid if 
+    // it is not empty. 
+    if (rect == iCropRect && !viewport.IsEmpty() && !extent.IsEmpty())
         {
-        case EVideoRotationNone:
-            aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dr));
-            aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(db));
-            aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dl));
-            aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dt));
-            break;
-        case EVideoRotationClockwise180:
-            aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dl));
-            aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dt));
-            aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dr));
-            aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(db));
-            break;
-        case EVideoRotationClockwise90:
-            aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(db));
-            aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dl));
-            aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(dt));
-            aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dr));
-            break;
-        case EVideoRotationClockwise270:
-            aViewport.iBr.iX -= (TInt) (wRatio * static_cast<TReal32>(dt));
-            aViewport.iBr.iY -= (TInt) (hRatio * static_cast<TReal32>(dr));
-            aViewport.iTl.iX += (TInt) (wRatio * static_cast<TReal32>(db));
-            aViewport.iTl.iY += (TInt) (hRatio * static_cast<TReal32>(dl));
-            break;
-        default:
-            // Should never get to default unless there's been some programming error.
-            User::Invariant();
-            break;
+        DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetBackgroundSurface - Calling SetBackgroundSurface");
+        err = aWindowData.iWindow->SetBackgroundSurface(aWindowData.iSurfaceConfig, ETrue);
         }
-    
-    // Clip the extent.
-    aExtent.Intersection(viewableArea);
-    
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CalculateExtentAndViewport ---"));
+
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetBackgroundSurface --- err %d", err);
+    return err;
     }
 
 TBool CMediaClientVideoDisplayBody::IsUsed() const
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsUsed +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsUsed ---"));
-	return (iEventHandler != NULL || iWindows.Count() > 0);
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsUsed +++");
+	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsUsed --- return %d", (iEventHandler || iClientWindows.Count() > 0));
+	return (iEventHandler || iClientWindows.Count() > 0);
 	}
 	
 
 TBool CMediaClientVideoDisplayBody::IsSurfaceCreated() const
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsSurfaceCreated +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::IsSurfaceCreated ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::IsSurfaceCreated +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::IsSurfaceCreated --- return %d", !(iSurfaceId.IsNull()));
 	return !(iSurfaceId.IsNull());
 	}
 		
 TInt CMediaClientVideoDisplayBody::DisplayId() const
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::DisplayId +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::DisplayId ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::DisplayId +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::DisplayId --- return %d", iDisplayId);
 	return iDisplayId;
 	}
 	
 TInt CMediaClientVideoDisplayBody::CompareByDisplay(const TInt* aDisplayId, const CMediaClientVideoDisplayBody& aDisplay)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CompareByDisplay +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CompareByDisplay ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::CompareByDisplay +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CompareByDisplay --- return %d", (*aDisplayId - aDisplay.DisplayId()));
 	return (*aDisplayId - aDisplay.DisplayId());
 	}
 		
 TInt CMediaClientVideoDisplayBody::Compare(const CMediaClientVideoDisplayBody& aLeft, const CMediaClientVideoDisplayBody& aRight)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Compare +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Compare ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::Compare +++");
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::Compare --- return %d", (aLeft.DisplayId() - aRight.DisplayId()));
 	return (aLeft.DisplayId() - aRight.DisplayId());
 	}
 	
 CFbsBitGc::TGraphicsOrientation CMediaClientVideoDisplayBody::ConvertRotation(TVideoRotation aRotation)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConvertRotation +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::ConvertRotation ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::ConvertRotation +++");
+	
+	CFbsBitGc::TGraphicsOrientation orientation;
+	
 	switch(aRotation)
 		{
 		case EVideoRotationNone:
-			return CFbsBitGc::EGraphicsOrientationNormal;
+		    orientation = CFbsBitGc::EGraphicsOrientationNormal;
+		    break;
 		case EVideoRotationClockwise90:
-			return CFbsBitGc::EGraphicsOrientationRotated270;
+		    orientation = CFbsBitGc::EGraphicsOrientationRotated270;
+		    break;
 		case EVideoRotationClockwise180:
-			return CFbsBitGc::EGraphicsOrientationRotated180;
+		    orientation = CFbsBitGc::EGraphicsOrientationRotated180;
+		    break;
 		case EVideoRotationClockwise270:
-			return CFbsBitGc::EGraphicsOrientationRotated90;
+		    orientation = CFbsBitGc::EGraphicsOrientationRotated90;
+		    break;
 		default:
 			// Should never get to default unless there's been some programming error.
 			User::Invariant();
 			// This is never reached, just to keep the compiler happy
-			return CFbsBitGc::EGraphicsOrientationNormal;
+			orientation = CFbsBitGc::EGraphicsOrientationNormal;
 		}
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::ConvertRotation --- return %d", orientation);	
+    return orientation;
 	}
 
 CMediaClientVideoDisplayBody* CMediaClientVideoDisplayBody::FindDisplayWithWindowL(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, const RWindowBase& aWindow)
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::FindDisplayWithWindowL +++"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::FindDisplayWithWindowL +++");
 	TInt count = aDisplays.Count();
 	
 	for (TInt i = 0; i < count; ++i)
 		{
 		CMediaClientVideoDisplayBody* display = aDisplays[i];
 	
-		if (display->iWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle) != KErrNotFound)
+		if (display->iClientWindows.Find(aWindow.WsHandle(), TWindowData::CompareByWsHandle) != KErrNotFound)
 			{
-			DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::FindDisplayWithWindowL ---"));
+			DEBUG_PRINTF2("CMediaClientVideoDisplayBody::FindDisplayWithWindowL window found at position ", i);
+			DEBUG_PRINTF("CMediaClientVideoDisplayBody::FindDisplayWithWindowL ---");
 			return display;	
 			}
 		}
@@ -813,87 +955,14 @@
 	
 RArray<CMediaClientVideoDisplayBody::TWindowData>& CMediaClientVideoDisplayBody::Windows()
 	{
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Windows +++"));
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::Windows ---"));
-	return iWindows;	
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::Windows +++");
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::Windows ---");
+	return iClientWindows;	
 	}
 
-void CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL(TRect& aExtent, TRect& aViewport, TRect& aExternalDisplayRect)
-    {
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL +++"));
-    
-    TWindowData windowData;
-    windowData.iVideoExtent = aExternalDisplayRect;
-    windowData.iRotation = EVideoRotationNone;
-    windowData.iAutoScaleType = EAutoScaleBestFit;
-    windowData.iHorizPos = EHorizontalAlignCenter;
-    windowData.iVertPos = EVerticalAlignCenter;
-    windowData.iClipRect = aExternalDisplayRect;
-    
-    aViewport = iCropRect;
-    // Viewport is 0 size, don't show any video
-    if (aViewport.Width() <= 0 || aViewport.Height() <= 0)
-        {
-        User::Leave(KErrArgument);
-        }
-    
-    CalculateExtentAndViewport(windowData, aExtent, aViewport);
-    
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayCalculateExtentAndViewportL ---"));
-    }
-
-void CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL(TBool aRemoveBackgroundSurface)
-    {
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL +++"));
-
-    if((iExtDisplayConnectionProvider == NULL) && (iWindows.Count() > 0))
-        {
-        iExtDisplayConnectionProvider = CExtDisplayConnectionProviderInterface::NewL(*this, iSurfaceId);
-        iExtDisplayConnected = iExtDisplayConnectionProvider->ExtDisplayConnectedL();
-        
-        if(iExtDisplayConnected && aRemoveBackgroundSurface)
-            {
-            RemoveBackgroundSurface(ETrue);
-            }
-        }
-
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::CreateExtDisplayConnProvAndRemoveSurfaceL ---"));
-    }
-   
-void CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL()
-    {
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL +++"));
-
-    if(iExtDisplayConnectionProvider != NULL)
-        {
-        delete iExtDisplayConnectionProvider;
-        REComSession::FinalClose();
-        iExtDisplayConnectionProvider = NULL;
-        iExtDisplayConnected = EFalse;
-        User::LeaveIfError(RedrawWindows(iCropRegion));
-        }
-
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProvAndRedrawL ---"));
-    }
-
-void CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv()
-    {
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv +++"));
-
-    if(iExtDisplayConnectionProvider != NULL)
-        {
-        delete iExtDisplayConnectionProvider;
-        REComSession::FinalClose();
-        iExtDisplayConnectionProvider = NULL;
-        iExtDisplayConnected = EFalse;
-        }
-
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::RemoveExtDisplayConnProv ---"));
-    }
-
 void CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL(TBool aControl)
     {
-    DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL +++ aControl=%d"), aControl);
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL +++ aControl=%d", aControl);
 
     // not supported
     if(!iExtDisplaySwitchingSupported)
@@ -902,7 +971,7 @@
         }
     
     // need active scheduler installed
-    if(CActiveScheduler::Current() == NULL)
+    if(!CActiveScheduler::Current())
         {
         User::Leave(KErrNotReady);
         }
@@ -911,48 +980,159 @@
         {
         iClientRequestedExtDisplaySwitching = aControl;
         
-        if(IsSurfaceCreated())
+        DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL SurfaceCreated %d", IsSurfaceCreated());
+        DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL Client window count %d", iClientWindows.Count());
+        DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL External Display Connected %d", iExtDisplayConnected);          
+        DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL Client Requested Ext Display Switching %d", iClientRequestedExtDisplaySwitching);          
+        
+        if(IsSurfaceCreated() && (iClientWindows.Count() > 0) && iExtDisplayConnected)
             {
             if(iClientRequestedExtDisplaySwitching)
                 {
-                CreateExtDisplayConnProvAndRemoveSurfaceL(ETrue);
+                TRAPD(err, CreateExtDisplayHandlerL());
+                DEBUG_PRINTF2("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL CreateExtDisplayHandlerL error %d", err);
+                if(err == KErrNone)
+                    {
+                    RemoveBackgroundSurface(ETrue);
+                    SetWindowArrayPtr2Ext();
+                    RedrawWindows(iCropRegion);
+                    }
                 }
-            else
+            else if(iExtDisplayHandler)
                 {
-                RemoveExtDisplayConnProvAndRedrawL();
+                RemoveBackgroundSurface(ETrue);
+                RemoveExtDisplayHandler();
+                SetWindowArrayPtr2Client();
+                RedrawWindows(iCropRegion);
                 }
             }
-        else
-            {
-            DEBUG_PRINT(_L("No Surface exists"));
-            }
         }
     
-    DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---"));
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetExternalDisplaySwitchingL ---");
     }
 
 void CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected(TBool aExtDisplayConnected)
 	{
-	DEBUG_PRINT2(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d"), aExtDisplayConnected);
+	DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected +++ aExtDisplayConnected=%d", aExtDisplayConnected);
 	
 	if(iExtDisplayConnected != aExtDisplayConnected)
 	    {
 	    iExtDisplayConnected = aExtDisplayConnected;
-	    if(iExtDisplayConnected)
-	        {
-	        RemoveBackgroundSurface(ETrue);
-	        }
-	    else
-	        {
-	        // ignore error - no need to tell provider - but lets log it in case it fails
-	        TInt err = RedrawWindows(iCropRegion);
-	        DEBUG_PRINT2(_L("RedrawWindows returned with %d"), err);
-	        }
+
+        if(IsSurfaceCreated() && (iClientWindows.Count() > 0) && iClientRequestedExtDisplaySwitching)
+            {
+            if(iExtDisplayConnected)
+                {
+                TRAPD(err, CreateExtDisplayHandlerL());
+                DEBUG_PRINTF2("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected CreateExtDisplayHandlerL error %d", err);
+                if(err == KErrNone)
+                    {
+                    RemoveBackgroundSurface(ETrue);
+                    SetWindowArrayPtr2Ext();
+                    RedrawWindows(iCropRegion);
+                    }
+                }
+            else if(iExtDisplayHandler)
+                {
+                RemoveBackgroundSurface(ETrue);
+                RemoveExtDisplayHandler();
+                SetWindowArrayPtr2Client();
+                RedrawWindows(iCropRegion);
+                }
+            }
 	    }
 	else
 	    {
-	    DEBUG_PRINT(_L("No change in ext display connection status"));
+	    DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected No change in ext display connection status");
 	    }
 	
-	DEBUG_PRINT(_L("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---"));
+	DEBUG_PRINTF("CMediaClientVideoDisplayBody::MedcpcExtDisplayNotifyConnected ---");
 	}
+
+void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client()
+    {
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client +++");
+
+    iWindowsArrayPtr = &iClientWindows;
+
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Client ---");
+    }
+
+void CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext()
+    {
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext +++");
+
+    iWindowsArrayPtr = &iExtDisplayWindows;
+
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::SetWindowArrayPtr2Ext ---");
+    }
+
+void CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL()
+    {
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL +++");
+
+    CMediaClientExtDisplayHandler* extDisplayHandler = CMediaClientExtDisplayHandler::NewL(iExtDisplayConnectionProvider->ExtDisplayId());
+    CleanupStack::PushL(extDisplayHandler);
+    
+    TWindowData windowData;
+    windowData.iWindow = extDisplayHandler->Window();
+    DEBUG_PRINTF2("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL - iWindow WsHandle 0x%X", windowData.iWindow->WsHandle());
+    
+    TRect externalDisplayRect(TPoint(0, 0), extDisplayHandler->DisplaySizeInPixels());
+    windowData.iClipRect = externalDisplayRect;
+    windowData.iVideoExtent = externalDisplayRect;
+    // windowData.iScaleWidth not required for EAutoScaleBestFit
+    // windowData.iScaleHeight not required for EAutoScaleBestFit
+    windowData.iRotation = EVideoRotationNone;
+    windowData.iAutoScaleType = EAutoScaleBestFit;
+    windowData.iHorizPos = EHorizontalAlignCenter;
+    windowData.iVertPos = EVerticalAlignCenter;
+    // windowData.iWindow2 not used        
+    
+    iExtDisplayWindows.AppendL(windowData);
+    CleanupStack::Pop(extDisplayHandler);
+    iExtDisplayHandler = extDisplayHandler;
+    
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayHandlerL ---");
+    }
+
+void CMediaClientVideoDisplayBody::RemoveExtDisplayHandler()
+    {
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayHandler +++");
+
+    delete iExtDisplayHandler;
+    iExtDisplayHandler = NULL;
+    iExtDisplayWindows.Reset();
+
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayHandler ---");
+    }
+
+void CMediaClientVideoDisplayBody::CreateExtDisplayPluginL()
+    {
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL +++");
+    
+    iExtDisplayConnectionProvider = CExtDisplayConnectionProviderInterface::NewL();
+    
+    if(iExtDisplayConnectionProvider)
+        {
+        iExtDisplaySwitchingSupported = ETrue;
+        iExtDisplayConnectionProvider->SetExtDisplayConnectionProviderCallback(*this);
+        iExtDisplayConnected = iExtDisplayConnectionProvider->ExtDisplayConnected();
+        }
+
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::CreateExtDisplayPluginL ---");
+    }
+
+void CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin()
+    {
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin +++");
+    
+    if(iExtDisplaySwitchingSupported)
+        {
+        delete iExtDisplayConnectionProvider;
+        iExtDisplayConnectionProvider = NULL;
+        iExtDisplaySwitchingSupported = EFalse;
+        iExtDisplayConnected = EFalse;
+        }    
+    DEBUG_PRINTF("CMediaClientVideoDisplayBody::RemoveExtDisplayPlugin ---");
+    }
--- a/mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.h	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/src/Client/Video/mediaclientvideodisplaybody.h	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -16,7 +16,7 @@
 #ifndef MEDIACLIENTVIDEODISPLAYBODY_H
 #define MEDIACLIENTVIDEODISPLAYBODY_H
 
-#include <w32std.h>
+#include "mediaclientextdisplayhandler.h"
 #include <graphics/surface.h>
 #include <graphics/surfaceconfiguration.h>
 #include <mmf/common/mmfvideosurfacecustomcommands.h>
@@ -92,8 +92,8 @@
 		};
 public:
 
-	static CMediaClientVideoDisplayBody* NewL(TInt aDisplayId);
-	static CMediaClientVideoDisplayBody* NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio);
+	static CMediaClientVideoDisplayBody* NewL(TInt aDisplayId, TBool aExtDisplaySwitchingControl);
+	static CMediaClientVideoDisplayBody* NewL(TInt aDisplayId, const TSurfaceId& aSurfaceId, const TRect& aCropRect, TVideoAspectRatio aAspectRatio, TBool aExtDisplaySwitchingControl);
 	
 	~CMediaClientVideoDisplayBody();
 	
@@ -129,7 +129,7 @@
 	CMediaClientVideoDisplayBody(TInt aDisplayId);
 	CMediaClientVideoDisplayBody(TInt aDisplayId, const TSurfaceId& aSurfaceId, const TRect& aCropRect,	TVideoAspectRatio aAspectRatio);
 	
-	void ConstructL();
+	void ConstructL(TBool aExtDisplaySwitchingControl);
 	
 	CFbsBitGc::TGraphicsOrientation ConvertRotation(TVideoRotation aRotation);
 	
@@ -141,15 +141,18 @@
 	static CMediaClientVideoDisplayBody* FindDisplayWithWindowL(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, const RWindowBase& aWindow);
 	TBool IsSurfaceCreated() const;
 	TInt SetBackgroundSurface(TWindowData& aWindowData, const TRect& aCropRegion);
-	void CalculateExtentAndViewport(const TWindowData& aWindowData, TRect& aExtent, TRect& aViewport);
 	TBool HasWindows() const;
 	
-    void CreateExtDisplayConnProvAndRemoveSurfaceL(TBool aRemoveBackgroundSurface);
-    void RemoveExtDisplayConnProvAndRedrawL();
-    void RemoveExtDisplayConnProv();
-    void MedcpcExtDisplayCalculateExtentAndViewportL(TRect& aExtent, TRect& aViewport, TRect& aExternalDisplayRect);
     void MedcpcExtDisplayNotifyConnected(TBool aExtDisplayConnected);
 
+    void UpdateCropRegionL(const TRect& aCropRegion, TInt aPos);
+    void CreateExtDisplayPluginL();
+    void RemoveExtDisplayPlugin();
+    void CreateExtDisplayHandlerL();
+    void RemoveExtDisplayHandler();
+    void SetWindowArrayPtr2Client();
+    void SetWindowArrayPtr2Ext();
+    
 private:
 
     MMMFSurfaceEventHandler* iEventHandler;
@@ -157,11 +160,15 @@
 	TSurfaceId iSurfaceId;
 	TRect iCropRect;
 	TVideoAspectRatio iAspectRatio;
-	RArray<TWindowData> iWindows;
+	
+	RArray<TWindowData> iClientWindows;
+	RArray<TWindowData> iExtDisplayWindows;
+	RArray<TWindowData>* iWindowsArrayPtr;
 	
 	TRect iCropRegion;
 	TBool iClientRequestedExtDisplaySwitching;
 	CExtDisplayConnectionProviderInterface* iExtDisplayConnectionProvider;
+	CMediaClientExtDisplayHandler* iExtDisplayHandler;
     TBool iExtDisplayConnected;
     TBool iExtDisplaySwitchingSupported;
 	
--- a/mmlibs/mmfw/src/Client/Video/mediaclientvideotrace.h	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/src/Client/Video/mediaclientvideotrace.h	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -22,9 +22,6 @@
 
 #include <e32debug.h>
 
-#define DEBUG_PRINT(a) RDebug::Print(a)
-#define DEBUG_PRINT2(a, b) RDebug::Print(a, b)
-
 #define DEBUG_PRINTF(a) RDebug::Printf(a)
 #define DEBUG_PRINTF2(a,b) RDebug::Printf(a,b)
 #define DEBUG_PRINTF3(a,b,c) RDebug::Printf(a,b,c)
@@ -33,9 +30,6 @@
 
 #else // __ENABLE_MEDIA_CLIENT_VIDEO_TRACE__
 
-#define DEBUG_PRINT(a)
-#define DEBUG_PRINT2(a, b)
-
 #define DEBUG_PRINTF(a)
 #define DEBUG_PRINTF2(a, b)
 #define DEBUG_PRINTF3(a, b, c)
--- a/mmlibs/mmfw/src/Client/Video/mmfclientvideoplayerbody.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/src/Client/Video/mmfclientvideoplayerbody.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -23,6 +23,7 @@
 #include "VideoPlayerBody.h"
 #include "mmfclientvideocommon.h"
 #include "mmfclientutility.h"
+#include "mediaclientvideotrace.h"
 
 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
 #include <mmf/common/mmfvideoenums.h>
@@ -69,10 +70,12 @@
 															 const TRect& aScreenRect,
 															 const TRect& aClipRect)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU1)++");
 	CBody* self = new(ELeave) CBody(aParent, aObserver, aScreenDevice.GetScreenNumber(), aPriority, aPref);
 	CleanupStack::PushL(self);
 	self->ConstructL(aWs, aScreenDevice, aWindow, aScreenRect, aClipRect);
 	CleanupStack::Pop();
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU1)--");
 	return self;
 	}
 
@@ -82,16 +85,19 @@
 															 TInt aPriority,
 															 TInt aPref)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU2)++");
 	CBody* self = new(ELeave) CBody(aParent, aObserver, aPriority, aPref);
 	CleanupStack::PushL(self);
 	self->ConstructL();
 	CleanupStack::Pop();
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU2)--");
 	return self;
 	}
 #endif // SYMBIAN_BUILD_GCE
 
 CVideoPlayerUtility::CBody::~CBody()
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::~CBody++");
 	Close();
 	
 	delete iControllerImplementationInformation;
@@ -104,10 +110,12 @@
 	delete iFrameBitmap;
 	if (iFbsSessionConnected)
 		iFbsSession.Disconnect();
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::~CBody--");
 	}
 
 void CVideoPlayerUtility::CBody::Close()
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Close++");
 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
 	DisableSubtitles();
 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
@@ -135,6 +143,7 @@
 	iControllerUid = KNullUid;
 	iControllerOpen = EFalse;
 	iDirectScreenAccessAbort = EFalse;
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Close--");
 	}
 
 CVideoPlayerUtility::CBody::CBody(CVideoPlayerUtility* aParent,
@@ -201,11 +210,13 @@
 
 void CVideoPlayerUtility::CBody::ConstructL()
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL1++");
 	CommonConstructL();
 	iFindAndOpenController = CMMFFindAndOpenController::NewL(*this);
 	iFindAndOpenController->SetSurfaceMode(iUsingVPU2, &iVideoPlaySurfaceSupportCustomCommands);
 	iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
 	iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EPlayback);
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL1--");
 	}
 
 #endif // SYMBIAN_BUILD_GCE
@@ -216,6 +227,7 @@
 						const TRect& aWindowRect,
 						const TRect& aClipRect)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL2++");
 	CommonConstructL();
 	
 	SetDisplayWindowL(aWs, aScreenDevice, aWindow, aWindowRect, aClipRect);
@@ -235,6 +247,7 @@
 #endif
 	iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
 	iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EPlayback);
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL2--");
 	}
 
 void CVideoPlayerUtility::CBody::CommonConstructL()
@@ -249,6 +262,7 @@
 
 void CVideoPlayerUtility::CBody::Reset() 
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Reset++");
 	Close();
 	
 	// reset all state variables
@@ -259,10 +273,12 @@
 	iGraphicsSurfaceSupported = EFalse;
 #endif
 	iControllerUid = KNullUid;
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Reset--");
 	}
 
 void CVideoPlayerUtility::CBody::SetAndUpdateWindow()
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAndUpdateWindow++");
 	if (iOpenError == KErrNone)	
 		{
 		// Set the display window and update display region if the controller doesn't support graphics surface. 		
@@ -273,6 +289,7 @@
 		{
 		iOpenError = iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion());
 		}
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAndUpdateWindow--");
 	}
 
 void CVideoPlayerUtility::CBody::MfaocComplete(		
@@ -282,6 +299,8 @@
 	TMMFMessageDestination* /*aSourceHandle*/, 
 	TMMFMessageDestination* /*aSinkHandle*/)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::MfaocComplete++");
+    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::MfaocComplete - aError %d, aControllerUid 0x%X", aError, aControllerUid.iUid);
 	iCallbackOpenReceived = ETrue;
 
 	// save the error in iOpenError -
@@ -295,6 +314,8 @@
 #ifdef SYMBIAN_BUILD_GCE
 		// Check if the graphics surfaces is supported
 		TInt err = CheckSurfaceSupported();
+
+		DEBUG_PRINTF4("CVideoPlayerUtility::CBody::MfaocComplete - Checked surfaces supported - Err %d, Surfaces supported %d, Using VPU2 %d", err, iGraphicsSurfaceSupported, iUsingVPU2);
 	
 		if (!iGraphicsSurfaceSupported)
 			{
@@ -397,24 +418,31 @@
 		iCallbackOpenReceived = EFalse;
 		iAsyncCallback->Signal(iOpenError, CMMFVideoPlayerCallback::EOpenCompleteEvent);
 		}
-
+	
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::MfaocComplete--");
 	}
 
 void CVideoPlayerUtility::CBody::OpenFileL(const TDesC& aFileName, TUid aControllerUid)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filename)++");
 	TMMFileSource filesource(aFileName, KDefaultContentObject, EPlay);
 	OpenFileL(filesource, aControllerUid);
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filename)--");
 	}
 	
 void CVideoPlayerUtility::CBody::OpenFileL(const RFile& aFile, TUid aControllerUid)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filehandle)++");
 	RFile& file = const_cast<RFile&>(aFile);
 	TMMFileHandleSource filehandlesource(file, KDefaultContentObject, EPlay);
 	OpenFileL(filehandlesource, aControllerUid);
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filehandle)--");
 	}
 
 void CVideoPlayerUtility::CBody::OpenFileL(const TMMSource& aSource, TUid aControllerUid)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (source)++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::OpenFileL - aControllerUid 0x%X", aControllerUid.iUid);
 	// Make sure we are closed
 	Reset();
 
@@ -434,6 +462,8 @@
 		{
 		iFindAndOpenController->OpenByFileSource(aSource);
 		}
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (source)--");
 	}
 	
 //
@@ -442,6 +472,7 @@
 //
 void CVideoPlayerUtility::CBody::OpenDesL(const TDesC8& aDescriptor, TUid aControllerUid)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenDesL++");
 	// Make sure we are closed
 	Reset();
 
@@ -461,10 +492,12 @@
 		{
 		iFindAndOpenController->OpenByDescriptor(aDescriptor);
 		}
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenDesL--");
 	}
 	
 void CVideoPlayerUtility::CBody::OpenUrlL(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType, TUid aControllerUid)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenUrlL++");
 	// Make sure we are closed
 	Reset();
 
@@ -487,16 +520,20 @@
 		iFindAndOpenController->OpenByUrl(aUrl, aIapId, aMimeType);
 
 	delete urlCfgBuffer;
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenUrlL--");
 	}
 
 void CVideoPlayerUtility::CBody::Play()
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Play++");
 	TInt err = iController.Prime();
 	if (err == KErrNone)
 		err = iController.Play();
 	if (err != KErrNone)
 	    {
 	    iAsyncCallback->Signal(err,CMMFVideoPlayerCallback::EPlayCompleteEvent);
+	    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play (exit 1)-- - Err %d", err);
 	    return;
 	    }
 	iState = EPlaying;
@@ -511,16 +548,20 @@
 			iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
 			}
 		}
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play-- - Err %d", err);
 	}
 
 void CVideoPlayerUtility::CBody::Play(const TTimeIntervalMicroSeconds& aStartTime, const TTimeIntervalMicroSeconds& aEndTime)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Play++");
+    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::Play - aStartTime %ld, aEndTime %ld", aStartTime.Int64(), aEndTime.Int64());
 	TInt err = iController.Prime();
 	if (err == KErrNone)
 	err = iVideoPlayControllerCustomCommands.Play(aStartTime, aEndTime);
 	if (err != KErrNone)
 	    {
 	    iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
+		DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play (exit1)-- - Err %d", err);
 	    return;
 	    }
 	iState = EPlaying;
@@ -535,20 +576,25 @@
 			iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
 			}
 		}
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play-- - Err %d", err);
 	}
 
 
 TInt CVideoPlayerUtility::CBody::Stop()
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Stop++");
 	TInt err = iController.Stop();
 	iState = EStopped;
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Stop-- - Err %d", err);
 	return err;
 	}
 
 void CVideoPlayerUtility::CBody::PauseL()
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PauseL++");
 	User::LeaveIfError(iController.Pause());
 	iState = EPaused;
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PauseL--");
 	}
 
 void CVideoPlayerUtility::CBody::SetVolumeL(TInt aVolume)
@@ -558,17 +604,27 @@
 
 void CVideoPlayerUtility::CBody::PrepareDSAL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL++");
 	CDirectScreenAccess* old = iDirectScreenAccess;
 	iDirectScreenAccess = CDirectScreenAccess::NewL(aWs,aScreenDevice,aWindow,*this);
 	delete old;
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL - Starting");
 	iDirectScreenAccess->StartL();
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL--");
 	}
 
 void CVideoPlayerUtility::CBody::SetDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice,
 							RWindowBase& aWindow, const TRect& aWindowRect,
 							const TRect& aClipRect)
 	{	
-	iWindowRect = aWindowRect;
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetDisplayWindowL++");
+    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindow abs pos %d,%d - width %d, height %d", aWindow.AbsPosition().iX, aWindow.AbsPosition().iY, aWindow.Size().iWidth, aWindow.Size().iHeight);
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindowRect %d,%d - %d,%d", aWindowRect.iTl.iX, aWindowRect.iTl.iY, aWindowRect.iBr.iX, aWindowRect.iBr.iY);
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aClipRect %d,%d - %d,%d", aClipRect.iTl.iX, aClipRect.iTl.iY, aClipRect.iBr.iX, aClipRect.iBr.iY);
+
+    iWindowRect = aWindowRect;
 	iClipRect = aClipRect;
 	
 #ifdef SYMBIAN_BUILD_GCE
@@ -630,6 +686,7 @@
 			}
 		}
 #endif
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetDisplayWindowL--");
 	}
 
 TReal32 CVideoPlayerUtility::CBody::VideoFrameRateL() const
@@ -668,6 +725,9 @@
 
 void CVideoPlayerUtility::CBody::SetRotationL(TVideoRotation aRotation)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aRotation %d", aRotation);
+
 #ifdef SYMBIAN_BUILD_GCE
 	if (!iGraphicsSurfaceSupported)
 		{
@@ -708,6 +768,8 @@
 #else 
 	User::LeaveIfError(iVideoPlayControllerCustomCommands.SetRotation(aRotation));
 #endif // SYMBIAN_BUILD_GCE
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL--");
 	}
 
 TVideoRotation CVideoPlayerUtility::CBody::RotationL() const
@@ -731,6 +793,9 @@
 
 void CVideoPlayerUtility::CBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, TBool aAntiAliasFiltering)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL");
+    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f, aAntiAliasFiltering %d", aWidthPercentage, aHeightPercentage, aAntiAliasFiltering);
+
 #ifdef SYMBIAN_BUILD_GCE
 	if (!iGraphicsSurfaceSupported)
 		{
@@ -755,6 +820,8 @@
 #else
 	User::LeaveIfError(iVideoPlayControllerCustomCommands.SetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
 #endif	// SYMBIAN_BUILD_GCE
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL--");
 	}
 
 void CVideoPlayerUtility::CBody::GetScaleFactorL(TReal32& aWidthPercentage, TReal32& aHeightPercentage, TBool& aAntiAliasFiltering) const
@@ -853,7 +920,10 @@
 
 void CVideoPlayerUtility::CBody::SetPriorityL(TInt aPriority, TInt aPref)
 	{
-	iPrioritySettings.iPref = aPref;
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPriorityL++");
+    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::SetPriorityL - aPriority %d, aPref %d", aPriority, aPref);
+
+    iPrioritySettings.iPref = aPref;
 	iPrioritySettings.iPriority = aPriority;
 
 	TInt err = iController.SetPrioritySettings(iPrioritySettings);
@@ -865,6 +935,7 @@
 		{
 		User::Leave(err);
 		}
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPriorityL--");
 	}
 
 void CVideoPlayerUtility::CBody::PriorityL(TInt & aPriority, TMdaPriorityPreference &aPref) const 
@@ -876,7 +947,10 @@
 
 void CVideoPlayerUtility::CBody::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPositionL++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetPositionL - aPosition %ld", aPosition.Int64());
 	User::LeaveIfError(iController.SetPosition(aPosition));
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPositionL--");
 	}
 
 
@@ -971,7 +1045,10 @@
 
 void CVideoPlayerUtility::CBody::HandleEvent(const TMMFEvent& aEvent)
 	{
-	if (aEvent.iEventType == KMMFEventCategoryVideoOpenComplete)
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::HandleEvent++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::HandleEvent - Event type 0x%X", aEvent.iEventType);
+
+    if (aEvent.iEventType == KMMFEventCategoryVideoOpenComplete)
 		{
 		// if we haven't had a MfaocComplete() callback yet,
 		// we need to delay the call back to the client
@@ -1066,12 +1143,16 @@
 	else 
 		// Pass on all unrecognised events to the client
 		iObserver.MvpuoEvent(aEvent);
+
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::HandleEvent--");
 	}
 
 #ifdef SYMBIAN_BUILD_GCE
 TInt CVideoPlayerUtility::CBody::SurfaceCreated()
 	{
-	TInt count = iActiveDisplays.Count();
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceCreated++");
+
+    TInt count = iActiveDisplays.Count();
 	TBool replaceSurface = !(iSurfaceId.IsNull());
 	TSurfaceId oldSurfaceId(iSurfaceId);
 	
@@ -1130,11 +1211,14 @@
             error = error2;
             }
         }
-    return error;
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceCreated--");
+	return error;
 	}
 
 TInt CVideoPlayerUtility::CBody::SurfaceParametersChanged()
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceParametersChanged++");
 	if (iSurfaceId.IsNull())
 		{
 		return KErrNotSupported;
@@ -1171,7 +1255,8 @@
 			error = error2;
 			}
 		}
-	return error;
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SurfaceParametersChanged-- - Error %d", error);
+    return error;
 	}
 		
 TInt CVideoPlayerUtility::CBody::SetAllBackgroundSurfaces()
@@ -1194,6 +1279,7 @@
 
 TInt CVideoPlayerUtility::CBody::RemoveSurface(TBool aControllerEvent)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveSurface++");
 	if (iSurfaceId.IsNull())
 		{
 		return KErrNotFound;
@@ -1209,6 +1295,7 @@
 
 	iSurfaceId = TSurfaceId::CreateNullId();
 	
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveSurface-- - Error %d", error);
 	return error;
 	}
 	
@@ -1402,7 +1489,14 @@
 							RWindow& aWindow, const TRect& aVideoExtent, 
 							const TRect& aWindowClipRect)
 	{
-	// set window and get display ID for the window
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL++");
+    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::AddDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow abs pos %d,%d - width %d, height %d", aWindow.AbsPosition().iX, aWindow.AbsPosition().iY, aWindow.Size().iWidth, aWindow.Size().iHeight);
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
+
+    // set window and get display ID for the window
 	TRect windowRect = TRect(aWindow.Size()); 
 	
 	// Check the rectangle is contained completely within the window
@@ -1415,11 +1509,19 @@
 		}
 		
 	DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, aWindowClipRect, aVideoExtent, &aWindow);
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL--");
 	}
 	
 void CVideoPlayerUtility::CBody::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
 	{
-	DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, TRect(aWindow.Size()), TRect(aWindow.Size()), &aWindow);
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL++");
+    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::AddDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow abs pos %d,%d - width %d, height %d", aWindow.AbsPosition().iX, aWindow.AbsPosition().iY, aWindow.Size().iWidth, aWindow.Size().iHeight);
+
+    DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, TRect(aWindow.Size()), TRect(aWindow.Size()), &aWindow);
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL--");
 	}
 
 void CVideoPlayerUtility::CBody::DoAddDisplayWindowL(RWsSession& aWs, TInt aDisplayId, RWindowBase& aWindow,
@@ -1450,11 +1552,11 @@
 		{
 		if(iSurfaceId.IsNull())
 			{
-			display = CMediaClientVideoDisplayBody::NewL(aDisplayId);
+			display = CMediaClientVideoDisplayBody::NewL(aDisplayId, ETrue);
 			}
 		else
 			{
-			display = CMediaClientVideoDisplayBody::NewL(aDisplayId, iSurfaceId, iSurfaceCropRect, iAspectRatio);
+			display = CMediaClientVideoDisplayBody::NewL(aDisplayId, iSurfaceId, iSurfaceCropRect, iAspectRatio, ETrue);
 			}
 		CleanupStack::PushL(display);
 		iActiveDisplays.InsertInOrderL(display, CMediaClientVideoDisplayBody::Compare);
@@ -1485,7 +1587,10 @@
 
 void CVideoPlayerUtility::CBody::RemoveDisplayWindow(RWindowBase& aWindow)
 	{
-	CMediaClientVideoDisplayBody* display = NULL;
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplayWindow++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveDisplayWindow - aWindow WsHandle 0x%X", aWindow.WsHandle());
+
+    CMediaClientVideoDisplayBody* display = NULL;
 	TRAPD(err, display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
 	
 	if (err == KErrNone)
@@ -1508,10 +1613,13 @@
 			}
 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
 		}	
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplayWindow--");
 	}
 
 void CVideoPlayerUtility::CBody::AddDisplayL(TInt aDisplay, MMMFSurfaceEventHandler& aEventHandler)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayL");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayL - aDisplay %d", aDisplay);
 	if (!iControllerOpen)
 		{
 		User::Leave(KErrNotReady);
@@ -1524,11 +1632,11 @@
 		CMediaClientVideoDisplayBody* display;
 		if(iSurfaceId.IsNull())
 			{
-			display = CMediaClientVideoDisplayBody::NewL(aDisplay);
+			display = CMediaClientVideoDisplayBody::NewL(aDisplay, ETrue);
 			}
 		else
 			{
-			display = CMediaClientVideoDisplayBody::NewL(aDisplay, iSurfaceId, iSurfaceCropRect, iAspectRatio);
+			display = CMediaClientVideoDisplayBody::NewL(aDisplay, iSurfaceId, iSurfaceCropRect, iAspectRatio, ETrue);
 			}
 		CleanupStack::PushL(display);
 		iActiveDisplays.InsertInOrderL(display, CMediaClientVideoDisplayBody::Compare);
@@ -1540,10 +1648,13 @@
 		User::LeaveIfError(err);
 		iActiveDisplays[err]->AddDisplayL(aEventHandler);
 		}
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayL--");
 	}
 
 void CVideoPlayerUtility::CBody::RemoveDisplay(TInt aDisplay)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplay++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveDisplay - aDisplay %d", aDisplay);
 	TInt pos = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
 	
 	if (pos >= KErrNone)
@@ -1557,6 +1668,7 @@
 			delete disp;
 			}
 		}
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplay--");
 	}
 
 void CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow(
@@ -1566,6 +1678,7 @@
             TRect& aToWindowRect,
             TRect& aToClipRect)
     {
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow++");
     TPoint windowOrigin = aWindow.AbsPosition();
     
     // window rect
@@ -1579,11 +1692,19 @@
     aToClipRect.iTl.iY = aFromClipRect.iTl.iY - windowOrigin.iY;
     aToClipRect.iBr.iX = aFromClipRect.iBr.iX - windowOrigin.iX;
     aToClipRect.iBr.iY = aFromClipRect.iBr.iY - windowOrigin.iY;
+
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow - New Window rect %d,%d - %d,%d", aToWindowRect.iTl.iX, aToWindowRect.iTl.iY, aToWindowRect.iBr.iX, aToWindowRect.iBr.iY);
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow - New Clip rect %d,%d - %d,%d", aToClipRect.iTl.iX, aToClipRect.iTl.iY, aToClipRect.iBr.iX, aToClipRect.iBr.iY);
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow--");
     }
 
 void CVideoPlayerUtility::CBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent)
 	{
-	// check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetVideoExtentL++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetVideoExtentL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetVideoExtentL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
+
+    // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
 	if (!iControllerOpen)
 		{
 		User::Leave(KErrNotReady);
@@ -1591,10 +1712,16 @@
 		
 	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
 	display->SetVideoExtentL(aWindow, aVideoExtent, iCropRegion);
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetVideoExtentL--");
 	}
 
 void CVideoPlayerUtility::CBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetWindowClipRectL++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetWindowClipRectL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetWindowClipRectL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
+
     // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
 	if (!iControllerOpen)
 		{
@@ -1623,6 +1750,8 @@
 #else
 	display->SetWindowClipRectL(aWindow, aWindowClipRect, iCropRegion);
 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetWindowClipRectL--");
 	}
 
 // Check if the controller supports the graphics surface. Has to be called after resource opened.
@@ -1658,18 +1787,28 @@
 	
 void CVideoPlayerUtility::CBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
 	{
-	if (!iControllerOpen)
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetAutoScaleL - aScaleType %d, aHorizPos %d, aVertPos %d", aScaleType, aHorizPos, aVertPos);
+
+    if (!iControllerOpen)
 		{
 		User::Leave(KErrNotReady);
 		}
 		
 	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
 	display->SetAutoScaleL(aWindow, aScaleType, aHorizPos, aVertPos, iCropRegion);
+
+	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL--");
 	}
 
 void CVideoPlayerUtility::CBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation)
 	{
-	if (!iControllerOpen)
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aRotation %d", aRotation);
+
+    if (!iControllerOpen)
 		{
 		User::Leave(KErrNotReady);
 		}
@@ -1688,6 +1827,7 @@
 #else
 	display->SetRotationL(aWindow, aRotation, iCropRegion);
 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL--");
 	}
 	
 TVideoRotation CVideoPlayerUtility::CBody::RotationL(const RWindowBase& aWindow) const
@@ -1702,6 +1842,9 @@
 	
 void CVideoPlayerUtility::CBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage)
 	{
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL++");
+    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetScaleFactorL - aWindow WsHandle 0x%X", aWindow.WsHandle());
+    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
 	if (!iControllerOpen)
 		{
 		User::Leave(KErrNotReady);
@@ -1709,6 +1852,7 @@
 		}
 	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
 	display->SetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage, iCropRegion);
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL--");
 	}
 	
 void CVideoPlayerUtility::CBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage) const
@@ -1852,7 +1996,10 @@
 	}
 void CVideoPlayerUtility::CBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
 	{
-	// Leave if Open is not yet called.
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL++");
+    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetAutoScaleL - aScaleType %d, aHorizPos %d, aVertPos %d", aScaleType, aHorizPos, aVertPos);
+
+    // Leave if Open is not yet called.
 	if(!iEventOpenReceived )
 		{
 		User::Leave(KErrNotReady);
@@ -1882,6 +2029,7 @@
 #else
 	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAutoScale(aScaleType, aHorizPos, aVertPos));
 #endif // SYMBIAN_BUILD_GCE
+    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL--");
 	}
 
 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
--- a/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestRecorder.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestRecorder.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1286,10 +1286,10 @@
 
 		if (iError != KErrOverflow)
 			{
-			ERR_PRINTF2( _L("CMdaAudioRecorderUtility failed with error %d"),iError );
-			CleanupStack::PopAndDestroy(recUtil);	
-			User::After(KOneSecond);
-			return ret;
+            ERR_PRINTF2( _L("CMdaAudioRecorderUtility failed with error %d"),iError );
+            CleanupStack::PopAndDestroy(recUtil);	
+            User::After(KOneSecond);
+            return ret;
 			}
 
 		TInt expectedLength=0;
@@ -1376,6 +1376,29 @@
 			else
 				{
 				INFO_PRINTF3(_L("Expected length %d, actual length %d"), expectedLength, actualLength);
+				
+				TInt machineType;
+	            TInt err = HAL::Get(HALData::EMachineUid, machineType);
+	            if (err)
+	                {
+				    ERR_PRINTF1(_L("Error Getting Device information"));
+				    iTestStepResult = EFail;
+				    CActiveScheduler::Stop();
+				    }
+	            else
+	                {
+                    if ((machineType == 0x102864F7) && (sampleRate == 8000))
+                        {
+                            // If test is running on a NaviEngine and uses 8K sample rate
+                            // then apply a tollerance when checking duration as we will
+                            // have applied conversion function.
+                            if ((iAudio->Length() >= expectedLength - 1000) &&
+                                 (iAudio->Length() <= expectedLength + 1000))
+                                {
+                                ret = EPass;
+                                }
+                        }
+	                }
 				}
 			}
 		else
--- a/mmlibs/mmfw/tsrc/mmfunittest/MmpFiles/TSU_MMF_VCLNT_01.mmp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/tsrc/mmfunittest/MmpFiles/TSU_MMF_VCLNT_01.mmp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -49,6 +49,7 @@
 source			../../../../src/Client/Video/mmfclientvideoplayer2.cpp
 source			../../../../src/Client/Video/mediaclientvideodisplaybody.cpp
 source			../../../../src/Client/Video/mediaclientextdisplayinterface.cpp
+source			../../../../src/Client/Video/mediaclientextdisplayhandler.cpp
 source			teststepvidplayereventhandler.cpp
 #endif
 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
--- a/mmlibs/mmfw/tsrc/mmfunittest/VCLNT/TSU_MMF_VCLNT_01/TestStepUnitMMFVidClient.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/tsrc/mmfunittest/VCLNT/TSU_MMF_VCLNT_01/TestStepUnitMMFVidClient.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -538,7 +538,7 @@
 
 	if (iVpu2)
 		{
-		aRect = iPlayer2->iBody->iActiveDisplays[0]->iWindows[0].iClipRect;
+		aRect = (*(iPlayer2->iBody->iActiveDisplays[0]->iWindowsArrayPtr))[0].iClipRect;
 		}
 #endif	
 	return KErrNone;
@@ -569,7 +569,7 @@
 
 	if (iVpu2)
 		{
-		aRect = iPlayer2->iBody->iActiveDisplays[0]->iWindows[0].iVideoExtent;
+		aRect = (*(iPlayer2->iBody->iActiveDisplays[0]->iWindowsArrayPtr))[0].iVideoExtent;
 		}
 #endif	
 	return KErrNone;
--- a/mmlibs/mmfw/tsrc/mmfunittest/aclnt/TSU_MMF_ACLNT_01/TestStepAudInStream.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/tsrc/mmfunittest/aclnt/TSU_MMF_ACLNT_01/TestStepAudInStream.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -135,7 +135,9 @@
 	{
 	// Issue reads on all available buffers
 	for (TInt ii=0; ii<KRecNumBuffer; ii++)
+	    {
 		iAudInStream->ReadL(iBufferList[ii]);
+	    }
 	}
 
 CTestStepAudInStream::CWriteBufferActive::CWriteBufferActive() : CActive(0)
@@ -1166,10 +1168,12 @@
 
 	TInt err = KErrNone;
 	TRAP(err, iAudInStream->SetDataTypeL(iTestParameters->iEncoding));
+
 	if (err != KErrNone)
 		 return EInconclusive;
 
 	iAudInStream->Open(NULL);
+	
 	CActiveScheduler::Start();
 
 	if (iError != KErrNone)
@@ -1217,7 +1221,7 @@
 	StartReadL();
 
 	CCallBackTimer* timer  = CCallBackTimer::NewL(TCallBack(stopActiveScheduler));
-	timer->After(5000000); // 3s
+	timer->After(5000000); // 5s
 	CActiveScheduler::Start();
 	delete timer;
 	if (iError != KErrNone)
@@ -1232,6 +1236,7 @@
 	CMdaAudioOutputStream* outputStream = CMdaAudioOutputStream::NewL(*this);
 	CleanupStack::PushL(outputStream);
 	TRAPD(err, outputStream->SetDataTypeL(iTestParameters->iEncoding));
+	
 	if (err != KErrNone)
 		{
 		CleanupStack::PopAndDestroy(1, outputStream);
@@ -1239,9 +1244,12 @@
 		}
 	outputStream->Open(NULL);
 	outputStream->SetVolume(outputStream->MaxVolume());
+
 	CActiveScheduler::Start(); // wait for open to complete
 	TInt size = 0;
+
 	User::LeaveIfError(iFile.Size(size));
+
 	// Read the entire file into a buffer - bit naughty but OK for test code
 	INFO_PRINTF2(_L("HBufC8:NewLC(size):  size=%d"), size);
 	HBufC8* buffer = HBufC8::NewLC(size);
--- a/mmlibs/mmfw/tsrc/mmfunittest/aclnt/TSU_MMF_ACLNT_01/TestStepPlayerPlay.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/tsrc/mmfunittest/aclnt/TSU_MMF_ACLNT_01/TestStepPlayerPlay.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -142,7 +142,7 @@
 	CleanupClosePushL(fs);
 	
 	RFile temp;
-	temp.Open(fs, iFileName, EFileRead|EFileWrite|EFileShareAny);
+	temp.Open(fs, iFileName, EFileRead|EFileWrite|EFileShareReadersOnly);
 	CleanupClosePushL(temp);
 	
     iPlayer = CMMFMdaAudioPlayerUtility::NewFilePlayerL(iFileName, *this);
--- a/mmlibs/mmfw/tsrc/mmfunittest/ctlfrm/mp3/MmfMP3Format/101F7D99.rss	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmlibs/mmfw/tsrc/mmfunittest/ctlfrm/mp3/MmfMP3Format/101F7D99.rss	Fri Mar 12 15:50:33 2010 +0200
@@ -33,13 +33,8 @@
 					implementation_uid = KUidMP3ImplementationFormat;  
 					version_no = 1;
 					display_name = "MP3 Raw Read Format||Copyright 2003 Symbian Ltd. All Rights Reserved.||";
-#ifdef SYMBIAN_MULTIMEDIA_A3FDEVSOUND
-					// KMmfUidPlayerAudioImplementationMp3 = 0x10272914 from PV
-					default_data = "0x10272914"; //Preferred Controller
-#else
 					// KMmfUidControllerAudio = 0x101F5022
 					default_data = "0x101f5022"; //Preferred Controller
-#endif
 					// KUidMediaTypeAudio = 0x101F5D07
 					// match by extension only
 					opaque_data = "<s>Symbian<i>0x101f5d07<e>.mp3<m>audio/mp3<m>audio/x-mp3";
@@ -56,15 +51,8 @@
 					implementation_uid = KUidMP3ImplementationFormatID3;
 					version_no = 1;
 					display_name = "MP3 ID3 Read Format||Copyright 2003 Symbian Ltd. All Rights Reserved.||";
-
-#ifdef SYMBIAN_MULTIMEDIA_A3FDEVSOUND
-					// KMmfUidPlayerAudioImplementationMp3 = 0x10272914 from PV
-					default_data = "0x10272914"; //Preferred Controller
-#else
 					// KMmfUidControllerAudio = 0x101F5022
 					default_data = "0x101f5022"; //Preferred Controller
-#endif
-
 					// match by ID3 header & extension
 					opaque_data = "<s>Symbian<i>0x101f5d07<e>.mp3<h>ID3?????????<m>audio/mp3<m>audio/x-mp3";
 					}
--- a/mmplugins/imagingplugins/codecs/GifCodec/GIFcodec.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmplugins/imagingplugins/codecs/GifCodec/GIFcodec.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -1,4 +1,4 @@
-// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -256,8 +256,8 @@
 		if (maskProc)
 			maskProc->FlushPixels();
 		pos = iFrameOffset;
-		
-		if(iGifImageControl && iGifImageControl->iTransparentColorIndex != KErrNotFound)
+		//in case of iFast64kMode == true, palette is of type T64KPixel
+		if(iGifImageControl && iGifImageControl->iTransparentColorIndex != KErrNotFound && !iFast64kMode)
 			{
 			// reset the transparency index
 			if (iTranspColIdx != KTranspColIdxNotPresent)
@@ -436,8 +436,6 @@
             i64KPalette[idx] = iPalette[idx]._Color64K();
             } 
             while (++idx < KGifColorTableMaxEntries);
-            
-        iPalette = reinterpret_cast<const TRgb*>( i64KPalette );
         }
         
     if (imageProc == NULL)
--- a/mmplugins/lib3gp/impl/src/file.cpp	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmplugins/lib3gp/impl/src/file.cpp	Fri Mar 12 15:50:33 2010 +0200
@@ -119,7 +119,6 @@
     // for compatibility, if opening in Any mode fails try more restrictive approach.
     if (file->Open(*fs, TPtrC((const TUint16 *)filename), EFileRead | EFileShareReadersOnly) != KErrNone)
     {
-        fs->Close();
         return -1;
     }
   }
@@ -183,7 +182,6 @@
 
   if (file->Replace(*fs, TPtrC((const TUint16 *)filename), EFileWrite|EFileShareExclusive ) != KErrNone)
   {
-    fs->Close();
     return -1;
   }
 
--- a/mmtestenv/mmtesttools/Build/mmbuildrom.pl	Sat Feb 20 00:20:15 2010 +0200
+++ b/mmtestenv/mmtesttools/Build/mmbuildrom.pl	Fri Mar 12 15:50:33 2010 +0200
@@ -336,7 +336,8 @@
 	if($uni ne "")
 		{
 		#Use Flexible Memory Model for UniCore
-		$command .= " -DWITH_FLEXIBLE_MM";
+		#Until base have fixed the issue related to this keep commented out.
+		#$command .= " -DWITH_FLEXIBLE_MM";
 		}
 	
 	$command .= " -D_NAND2" if ($nand ne "" && $arm ne "");