os/mm/mmlibs/mmfw/src/Client/Video/mmfclientvideoplayerbody.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/src/Client/Video/mmfclientvideoplayerbody.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2280 @@
     1.4 +// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +
    1.20 +#include <mmf/common/mmfstandardcustomcommands.h>  
    1.21 +#include <mmf/common/mmfdrmcustomcommands.h>  
    1.22 +#include <mmf/common/mmfvideo.h>
    1.23 +#include <mmf/server/mmfdes.h>
    1.24 +#include <mmf/server/mmffile.h>
    1.25 +#include "mmfvideocallback.h"
    1.26 +#include "VideoPlayerBody.h"
    1.27 +#include "mmfclientvideocommon.h"
    1.28 +#include "mmfclientutility.h"
    1.29 +#include "mediaclientvideotrace.h"
    1.30 +
    1.31 +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    1.32 +#include <mmf/common/mmfvideoenums.h>
    1.33 +#endif
    1.34 +
    1.35 +#ifdef SYMBIAN_BUILD_GCE
    1.36 +#include <videoplayer2.h>
    1.37 +#include <surfaceeventhandler.h>
    1.38 +#endif
    1.39 +
    1.40 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
    1.41 +#include <mmf/common/mmfpaniccodes.h>
    1.42 +#include "mmfsubtitleutility.h"
    1.43 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
    1.44 +
    1.45 +using namespace ContentAccess;
    1.46 +
    1.47 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
    1.48 +
    1.49 +#ifdef _DEBUG
    1.50 +void VPUDebugPanicOrLeaveL(TInt aVPUPanicCode, TInt aLeaveCode)
    1.51 +	{
    1.52 +	_LIT(KMMFVideoPlayerUtilityPanicCategory, "MMFVideoPlayUtil");
    1.53 +	User::Panic(KMMFVideoPlayerUtilityPanicCategory, aVPUPanicCode);
    1.54 +	User::Leave(aLeaveCode); // added for leavescan
    1.55 +	}
    1.56 +
    1.57 +#else
    1.58 +void VPUDebugPanicOrLeaveL(TInt /*aVPUPanicCode*/, TInt aLeaveCode)
    1.59 +	{
    1.60 +	User::Leave(aLeaveCode);
    1.61 +	}
    1.62 +#endif //_DEBUG
    1.63 +
    1.64 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
    1.65 +
    1.66 +CVideoPlayerUtility::CBody* CVideoPlayerUtility::CBody::NewL(CVideoPlayerUtility* aParent,
    1.67 +															 MVideoPlayerUtilityObserver& aObserver,
    1.68 +															 TInt aPriority,
    1.69 +															 TInt aPref,
    1.70 +															 RWsSession& aWs,
    1.71 +															 CWsScreenDevice& aScreenDevice,
    1.72 +															 RWindowBase& aWindow,
    1.73 +															 const TRect& aScreenRect,
    1.74 +															 const TRect& aClipRect)
    1.75 +	{
    1.76 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU1)++");
    1.77 +	CBody* self = new(ELeave) CBody(aParent, aObserver, aScreenDevice.GetScreenNumber(), aPriority, aPref);
    1.78 +	CleanupStack::PushL(self);
    1.79 +	self->ConstructL(aWs, aScreenDevice, aWindow, aScreenRect, aClipRect);
    1.80 +	CleanupStack::Pop();
    1.81 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU1)--");
    1.82 +	return self;
    1.83 +	}
    1.84 +
    1.85 +#ifdef SYMBIAN_BUILD_GCE
    1.86 +CVideoPlayerUtility::CBody* CVideoPlayerUtility::CBody::NewL(CVideoPlayerUtility2* aParent,
    1.87 +															 MVideoPlayerUtilityObserver& aObserver,
    1.88 +															 TInt aPriority,
    1.89 +															 TInt aPref)
    1.90 +	{
    1.91 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU2)++");
    1.92 +	CBody* self = new(ELeave) CBody(aParent, aObserver, aPriority, aPref);
    1.93 +	CleanupStack::PushL(self);
    1.94 +	self->ConstructL();
    1.95 +	CleanupStack::Pop();
    1.96 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU2)--");
    1.97 +	return self;
    1.98 +	}
    1.99 +#endif // SYMBIAN_BUILD_GCE
   1.100 +
   1.101 +CVideoPlayerUtility::CBody::~CBody()
   1.102 +	{
   1.103 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::~CBody++");
   1.104 +	Close();
   1.105 +	
   1.106 +	delete iControllerImplementationInformation;
   1.107 +	delete iDirectScreenAccess;
   1.108 +	delete iFindAndOpenController;
   1.109 +	delete iControllerEventMonitor;
   1.110 +	delete iFrameCallback;
   1.111 +	delete iAsyncCallback;
   1.112 +	delete iMimeType;
   1.113 +	delete iFrameBitmap;
   1.114 +	if (iFbsSessionConnected)
   1.115 +		iFbsSession.Disconnect();
   1.116 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::~CBody--");
   1.117 +	}
   1.118 +
   1.119 +void CVideoPlayerUtility::CBody::Close()
   1.120 +	{
   1.121 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Close++");
   1.122 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   1.123 +	DisableSubtitles();
   1.124 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   1.125 +
   1.126 +	if (iAsyncCallback)
   1.127 +		iAsyncCallback->Cancel();
   1.128 +	if (iFrameCallback)
   1.129 +		iFrameCallback->Cancel();
   1.130 +	if (iFindAndOpenController)
   1.131 +		iFindAndOpenController->Close();
   1.132 +	if (iControllerEventMonitor)
   1.133 +		iControllerEventMonitor->Cancel();
   1.134 +	if(iControllerImplementationInformation)
   1.135 +		{
   1.136 +		delete iControllerImplementationInformation;
   1.137 +		iControllerImplementationInformation = NULL;
   1.138 +		}
   1.139 +
   1.140 +#ifdef SYMBIAN_BUILD_GCE
   1.141 +	iActiveDisplays.ResetAndDestroy();
   1.142 +	iSurfaceId = TSurfaceId::CreateNullId();
   1.143 +#endif
   1.144 +
   1.145 +	iController.Close();	
   1.146 +	iControllerUid = KNullUid;
   1.147 +	iControllerOpen = EFalse;
   1.148 +	iDirectScreenAccessAbort = EFalse;
   1.149 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Close--");
   1.150 +	}
   1.151 +
   1.152 +CVideoPlayerUtility::CBody::CBody(CVideoPlayerUtility* aParent,
   1.153 +								  MVideoPlayerUtilityObserver& aObserver,
   1.154 +								  TInt aScreenNumber,
   1.155 +								  TInt aPriority,
   1.156 +								  TInt aPref) : 
   1.157 +	iVideoControllerCustomCommands(iController),
   1.158 +	iVideoPlayControllerCustomCommands(iController),
   1.159 +	iAudioPlayDeviceCustomCommands(iController),
   1.160 +	iAudioRecordDeviceCustomCommands(iController),
   1.161 +	iVideoDRMExtCustomCommands(iController),
   1.162 +	iDRMCustomCommands(iController),
   1.163 +	iVideoPlayControllerExtCustomCommands(iController),	
   1.164 +	iNotificationRegistrationCommands(iController),
   1.165 +#ifdef SYMBIAN_BUILD_GCE
   1.166 +	iVideoPlaySurfaceSupportCustomCommands(iController),
   1.167 +#endif
   1.168 +	iArnEventHolder(KNullUid),
   1.169 +	iVideoSetInitScreenCustomCommands(iController),
   1.170 +	iObserver(aObserver),
   1.171 +	iState(EStopped),
   1.172 +	iParent(aParent),
   1.173 +	iScreenNumber(aScreenNumber)
   1.174 +#ifdef SYMBIAN_BUILD_GCE
   1.175 +	,iGlobalScaleWidth(100.0f),
   1.176 +	iGlobalScaleHeight(100.0f),
   1.177 +	iGlobalAutoScaleType(EAutoScaleBestFit),  // Really need some platform specific way of defining this. Not everyone will want it.
   1.178 +	iGlobalHorizPos(EHorizontalAlignCenter),
   1.179 +	iGlobalVertPos(EVerticalAlignCenter)
   1.180 +#endif
   1.181 +	{
   1.182 +	iPrioritySettings.iPriority = aPriority;
   1.183 +	iPrioritySettings.iPref = aPref;
   1.184 +	}
   1.185 +
   1.186 +#ifdef SYMBIAN_BUILD_GCE
   1.187 +CVideoPlayerUtility::CBody::CBody(CVideoPlayerUtility2* aParent,
   1.188 +				MVideoPlayerUtilityObserver& aObserver,
   1.189 +				TInt aPriority,
   1.190 +				TInt aPref) : 
   1.191 +	iVideoControllerCustomCommands(iController),
   1.192 +	iVideoPlayControllerCustomCommands(iController),
   1.193 +	iAudioPlayDeviceCustomCommands(iController),
   1.194 +	iAudioRecordDeviceCustomCommands(iController),
   1.195 +	iVideoDRMExtCustomCommands(iController),
   1.196 +	iDRMCustomCommands(iController),
   1.197 +	iVideoPlayControllerExtCustomCommands(iController),
   1.198 +	iNotificationRegistrationCommands(iController),
   1.199 +	iVideoPlaySurfaceSupportCustomCommands(iController),
   1.200 +	iArnEventHolder(KNullUid),
   1.201 +	iVideoSetInitScreenCustomCommands(iController),
   1.202 +	iObserver(aObserver),
   1.203 +	iState(EStopped),
   1.204 +	iParent(aParent),
   1.205 +	iUsingVPU2(ETrue),
   1.206 +	iGlobalScaleWidth(100.0f),
   1.207 +	iGlobalScaleHeight(100.0f),
   1.208 +	iGlobalHorizPos(EHorizontalAlignCenter),
   1.209 +	iGlobalVertPos(EVerticalAlignCenter)
   1.210 +	{
   1.211 +	iPrioritySettings.iPriority = aPriority;
   1.212 +	iPrioritySettings.iPref = aPref;
   1.213 +	}
   1.214 +
   1.215 +void CVideoPlayerUtility::CBody::ConstructL()
   1.216 +	{
   1.217 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL1++");
   1.218 +	CommonConstructL();
   1.219 +	iFindAndOpenController = CMMFFindAndOpenController::NewL(*this);
   1.220 +	iFindAndOpenController->SetSurfaceMode(iUsingVPU2, &iVideoPlaySurfaceSupportCustomCommands);
   1.221 +	iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
   1.222 +	iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EPlayback);
   1.223 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL1--");
   1.224 +	}
   1.225 +
   1.226 +#endif // SYMBIAN_BUILD_GCE
   1.227 +
   1.228 +void CVideoPlayerUtility::CBody::ConstructL(RWsSession& aWs,
   1.229 +						CWsScreenDevice& aScreenDevice,
   1.230 +						RWindowBase& aWindow,
   1.231 +						const TRect& aWindowRect,
   1.232 +						const TRect& aClipRect)
   1.233 +	{
   1.234 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL2++");
   1.235 +	CommonConstructL();
   1.236 +	
   1.237 +	SetDisplayWindowL(aWs, aScreenDevice, aWindow, aWindowRect, aClipRect);
   1.238 +	iFindAndOpenController = CMMFFindAndOpenController::NewL(*this);
   1.239 +#ifdef SYMBIAN_BUILD_GCE	
   1.240 +	iFindAndOpenController->SetSurfaceMode(iUsingVPU2, &iVideoPlaySurfaceSupportCustomCommands);
   1.241 +	
   1.242 +	// If we open a controller with surface support we may render to surfaces.  We need to store these
   1.243 +	// so we can add the display as a surface rendering target.
   1.244 +
   1.245 +	iWs = &aWs;
   1.246 +	iDisplayId = aScreenDevice.GetScreenNumber();
   1.247 +	iWindow = &aWindow;
   1.248 +	iWindowRect = aWindowRect;
   1.249 +	iClipRect = aClipRect;	
   1.250 +
   1.251 +#endif
   1.252 +	iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
   1.253 +	iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EPlayback);
   1.254 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL2--");
   1.255 +	}
   1.256 +
   1.257 +void CVideoPlayerUtility::CBody::CommonConstructL()
   1.258 +	{
   1.259 +	iControllerEventMonitor = CMMFControllerEventMonitor::NewL(*this, iController);
   1.260 +	iMimeType = HBufC8::NewL(KMaxMimeTypeLength);
   1.261 +	iAsyncCallback = new (ELeave) CMMFVideoPlayerCallback(iObserver);
   1.262 +	iFrameCallback = new (ELeave) CMMFVideoPlayerCallback(iObserver);
   1.263 +	User::LeaveIfError(iFbsSession.Connect());
   1.264 +	iFbsSessionConnected = ETrue;
   1.265 +	}
   1.266 +
   1.267 +void CVideoPlayerUtility::CBody::Reset() 
   1.268 +	{
   1.269 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Reset++");
   1.270 +	Close();
   1.271 +	
   1.272 +	// reset all state variables
   1.273 +	iEventOpenReceived = EFalse;
   1.274 +	iCallbackOpenReceived = EFalse;
   1.275 +	iOpenError = KErrNone;
   1.276 +#ifdef SYMBIAN_BUILD_GCE
   1.277 +	iGraphicsSurfaceSupported = EFalse;
   1.278 +#endif
   1.279 +	iControllerUid = KNullUid;
   1.280 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Reset--");
   1.281 +	}
   1.282 +
   1.283 +void CVideoPlayerUtility::CBody::SetAndUpdateWindow()
   1.284 +	{
   1.285 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAndUpdateWindow++");
   1.286 +	if (iOpenError == KErrNone)	
   1.287 +		{
   1.288 +		// Set the display window and update display region if the controller doesn't support graphics surface. 		
   1.289 +		iOpenError = iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect, iClipRect);
   1.290 +		}
   1.291 +
   1.292 +	if (iOpenError == KErrNone && iDirectScreenAccess && iDirectScreenAccess->DrawingRegion())
   1.293 +		{
   1.294 +		iOpenError = iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion());
   1.295 +		}
   1.296 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAndUpdateWindow--");
   1.297 +	}
   1.298 +
   1.299 +void CVideoPlayerUtility::CBody::MfaocComplete(		
   1.300 +	TInt& aError, 
   1.301 +	RMMFController*	/*aController*/,
   1.302 +	TUid aControllerUid, 
   1.303 +	TMMFMessageDestination* /*aSourceHandle*/, 
   1.304 +	TMMFMessageDestination* /*aSinkHandle*/)
   1.305 +	{
   1.306 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::MfaocComplete++");
   1.307 +    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::MfaocComplete - aError %d, aControllerUid 0x%X", aError, aControllerUid.iUid);
   1.308 +	iCallbackOpenReceived = ETrue;
   1.309 +
   1.310 +	// save the error in iOpenError -
   1.311 +	// unless HandleEvent(KMMFEventCategoryVideoOpenComplete) 
   1.312 +	// has reported an error already
   1.313 +	if (iOpenError == KErrNone)
   1.314 +		iOpenError = aError;
   1.315 +	
   1.316 +	if (iOpenError == KErrNone)
   1.317 +		{
   1.318 +#ifdef SYMBIAN_BUILD_GCE
   1.319 +		// Check if the graphics surfaces is supported
   1.320 +		TInt err = CheckSurfaceSupported();
   1.321 +
   1.322 +		DEBUG_PRINTF4("CVideoPlayerUtility::CBody::MfaocComplete - Checked surfaces supported - Err %d, Surfaces supported %d, Using VPU2 %d", err, iGraphicsSurfaceSupported, iUsingVPU2);
   1.323 +	
   1.324 +		if (!iGraphicsSurfaceSupported)
   1.325 +			{
   1.326 +			if (err != KErrNone && iUsingVPU2)
   1.327 +				{
   1.328 +				// Set KErrNotSupported if the controller doesn't support graphics surface and 
   1.329 +				// the open source is using CVideoPlayerUtility2
   1.330 +				iOpenError = err;
   1.331 +				}
   1.332 +			else
   1.333 +				{
   1.334 +				SetAndUpdateWindow();
   1.335 +				}
   1.336 +			}
   1.337 +#else
   1.338 +		SetAndUpdateWindow();
   1.339 +#endif // SYMBIAN_BUILD_GCE	
   1.340 +	
   1.341 +		// now that the controller is open
   1.342 +		if (iOpenError == KErrNone)
   1.343 +			{
   1.344 +			iControllerOpen = ETrue;
   1.345 +			iControllerUid = aControllerUid;
   1.346 +
   1.347 +#ifdef SYMBIAN_BUILD_GCE		
   1.348 +			// We are using a controller that supports graphics surfaces but are not in surface mode.  
   1.349 +			// Call AddDisplay so we can render to surfaces using the CVideoUtility API.
   1.350 +			if (iGraphicsSurfaceSupported && !iUsingVPU2)
   1.351 +				{
   1.352 +				if (iDirectScreenAccess)
   1.353 +					{
   1.354 +		 			iDirectScreenAccess->Cancel();
   1.355 +					}
   1.356 +				
   1.357 +		        // When using surfaces for CVPU we use DoAddDisplayWindowL() which requires clip rectangle and video extent
   1.358 +		        // as arguments. Video extent is not supported by CVPU so aWindowRect is used instead. This function
   1.359 +		        // assumes these args are relative to the window. However they are relative to the display and must be
   1.360 +		        // converted.
   1.361 +		        TRect windowRectRelativeToWindow;
   1.362 +		        TRect clipRectRelativeToWindow;     
   1.363 +		        ConvertFromRelativeToDisplayToRelativeToWindow(*iWindow, iWindowRect, iClipRect, windowRectRelativeToWindow, clipRectRelativeToWindow);
   1.364 +
   1.365 +				TRAP(iOpenError, DoAddDisplayWindowL(*iWs, iDisplayId, *iWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL));				
   1.366 +				}
   1.367 +#endif		
   1.368 +			}
   1.369 +		// If an error occurred in any of the above, try for next controller if present
   1.370 +		// in the selection list.
   1.371 +		else
   1.372 +			{
   1.373 +			if(iFindAndOpenController->ControllerIndex() < (iFindAndOpenController->ControllerCount())-1)
   1.374 +				{
   1.375 +				aError = iOpenError;
   1.376 +				
   1.377 +				if (iAsyncCallback)
   1.378 +					{
   1.379 +					iAsyncCallback->Cancel();
   1.380 +					}
   1.381 +		
   1.382 +				if (iControllerEventMonitor)
   1.383 +					{
   1.384 +					iControllerEventMonitor->Cancel();
   1.385 +					}
   1.386 +				iOpenError = KErrNone;
   1.387 +					
   1.388 +				return;
   1.389 +				}
   1.390 +				
   1.391 +			Close();
   1.392 +			}
   1.393 +		}
   1.394 +
   1.395 +	if(iOpenError != KErrNone && !iControllerOpen)
   1.396 +		{
   1.397 +		if (iFindAndOpenController)	
   1.398 +			{
   1.399 +			//if try next controller was called when specific controller uid was 
   1.400 +			//given, skip the searching and report error.
   1.401 +			if(!iFindAndOpenController->StopTryLoadController()) 
   1.402 +				{
   1.403 +				if( !(aError == KErrNoMemory || aError == KErrCancel ) ) 
   1.404 +					{
   1.405 +					if(iFindAndOpenController->ControllerIndex() < (iFindAndOpenController->ControllerCount())-1)
   1.406 +						{
   1.407 +						aError = iOpenError;   // Actually tries to load controller
   1.408 +						iOpenError = KErrNone;
   1.409 +						return;
   1.410 +						}
   1.411 +					}
   1.412 +				}
   1.413 +			}
   1.414 +		}
   1.415 +	
   1.416 +	// if we've already received the open complete event
   1.417 +	// call the client now (otherwise wait for it)
   1.418 +	if (iEventOpenReceived || iOpenError != KErrNone)
   1.419 +		{
   1.420 +		// stop a subsequent HandleEvent(KMMFEventCategoryVideoOpenComplete) 
   1.421 +		// from issuing another callback to client
   1.422 +		iCallbackOpenReceived = EFalse;
   1.423 +		iAsyncCallback->Signal(iOpenError, CMMFVideoPlayerCallback::EOpenCompleteEvent);
   1.424 +		}
   1.425 +	
   1.426 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::MfaocComplete--");
   1.427 +	}
   1.428 +
   1.429 +void CVideoPlayerUtility::CBody::OpenFileL(const TDesC& aFileName, TUid aControllerUid)
   1.430 +	{
   1.431 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filename)++");
   1.432 +	TMMFileSource filesource(aFileName, KDefaultContentObject, EPlay);
   1.433 +	OpenFileL(filesource, aControllerUid);
   1.434 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filename)--");
   1.435 +	}
   1.436 +	
   1.437 +void CVideoPlayerUtility::CBody::OpenFileL(const RFile& aFile, TUid aControllerUid)
   1.438 +	{
   1.439 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filehandle)++");
   1.440 +	RFile& file = const_cast<RFile&>(aFile);
   1.441 +	TMMFileHandleSource filehandlesource(file, KDefaultContentObject, EPlay);
   1.442 +	OpenFileL(filehandlesource, aControllerUid);
   1.443 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filehandle)--");
   1.444 +	}
   1.445 +
   1.446 +void CVideoPlayerUtility::CBody::OpenFileL(const TMMSource& aSource, TUid aControllerUid)
   1.447 +	{
   1.448 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (source)++");
   1.449 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::OpenFileL - aControllerUid 0x%X", aControllerUid.iUid);
   1.450 +	// Make sure we are closed
   1.451 +	Reset();
   1.452 +
   1.453 +	iFindAndOpenController->ConfigureSourceSink(
   1.454 +		aSource,
   1.455 +		CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput));
   1.456 +
   1.457 +#ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
   1.458 +	iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
   1.459 +#endif
   1.460 +
   1.461 +	if (aControllerUid != KNullUid) 
   1.462 +		{
   1.463 +		iFindAndOpenController->OpenByControllerUid(aControllerUid);
   1.464 +		}
   1.465 +	else
   1.466 +		{
   1.467 +		iFindAndOpenController->OpenByFileSource(aSource);
   1.468 +		}
   1.469 +
   1.470 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (source)--");
   1.471 +	}
   1.472 +	
   1.473 +//
   1.474 +// This method launches and initializes plugin controller based on the stream 
   1.475 +// source header passed in the descriptor buffer.
   1.476 +//
   1.477 +void CVideoPlayerUtility::CBody::OpenDesL(const TDesC8& aDescriptor, TUid aControllerUid)
   1.478 +	{
   1.479 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenDesL++");
   1.480 +	// Make sure we are closed
   1.481 +	Reset();
   1.482 +
   1.483 +	iFindAndOpenController->ConfigureSourceSink(
   1.484 +		CMMFFindAndOpenController::TSourceSink(KUidMmfDescriptorSource, CMMFFindAndOpenController::GetConfigDescriptor(aDescriptor)), 
   1.485 +		CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput, KNullDesC8));
   1.486 +	
   1.487 +#ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
   1.488 +	iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
   1.489 +#endif
   1.490 +		
   1.491 +	if (aControllerUid!=KNullUid)
   1.492 +		{
   1.493 +		iFindAndOpenController->OpenByControllerUid(aControllerUid);
   1.494 +		}
   1.495 +	else
   1.496 +		{
   1.497 +		iFindAndOpenController->OpenByDescriptor(aDescriptor);
   1.498 +		}
   1.499 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenDesL--");
   1.500 +	}
   1.501 +	
   1.502 +void CVideoPlayerUtility::CBody::OpenUrlL(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType, TUid aControllerUid)
   1.503 +	{
   1.504 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenUrlL++");
   1.505 +	// Make sure we are closed
   1.506 +	Reset();
   1.507 +
   1.508 +	CBufFlat* urlCfgBuffer = NULL;
   1.509 +    CMMFFindAndOpenController::GetConfigUrlL(urlCfgBuffer, aUrl, aIapId);
   1.510 +
   1.511 +	iFindAndOpenController->ConfigureSourceSink(
   1.512 +		CMMFFindAndOpenController::TSourceSink(KUidMmfUrlSource, urlCfgBuffer->Ptr(0)), 
   1.513 +		CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput, KNullDesC8));
   1.514 +	
   1.515 +#ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
   1.516 +	iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
   1.517 +#endif
   1.518 +		
   1.519 +	if (aControllerUid!=KNullUid)
   1.520 +		{
   1.521 +		iFindAndOpenController->OpenByControllerUid(aControllerUid);
   1.522 +		}
   1.523 +	else
   1.524 +		iFindAndOpenController->OpenByUrl(aUrl, aIapId, aMimeType);
   1.525 +
   1.526 +	delete urlCfgBuffer;
   1.527 +
   1.528 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenUrlL--");
   1.529 +	}
   1.530 +
   1.531 +void CVideoPlayerUtility::CBody::Play()
   1.532 +	{
   1.533 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Play++");
   1.534 +	TInt err = iController.Prime();
   1.535 +	if (err == KErrNone)
   1.536 +		err = iController.Play();
   1.537 +	if (err != KErrNone)
   1.538 +	    {
   1.539 +	    iAsyncCallback->Signal(err,CMMFVideoPlayerCallback::EPlayCompleteEvent);
   1.540 +	    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play (exit 1)-- - Err %d", err);
   1.541 +	    return;
   1.542 +	    }
   1.543 +	iState = EPlaying;
   1.544 +	//If Audio Resource Notification request is pending - attempt now
   1.545 +	if(iArnEventHolder != KNullUid)
   1.546 +		{
   1.547 +		err = iNotificationRegistrationCommands.RegisterAsClient(iArnEventHolder, iNotificationDataHolder);
   1.548 +		iArnEventHolder = KNullUid;
   1.549 +		iNotificationDataHolder = KNullDesC8;
   1.550 +		if(err != KErrNone)
   1.551 +			{
   1.552 +			iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
   1.553 +			}
   1.554 +		}
   1.555 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play-- - Err %d", err);
   1.556 +	}
   1.557 +
   1.558 +void CVideoPlayerUtility::CBody::Play(const TTimeIntervalMicroSeconds& aStartTime, const TTimeIntervalMicroSeconds& aEndTime)
   1.559 +	{
   1.560 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Play++");
   1.561 +    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::Play - aStartTime %ld, aEndTime %ld", aStartTime.Int64(), aEndTime.Int64());
   1.562 +	TInt err = iController.Prime();
   1.563 +	if (err == KErrNone)
   1.564 +	err = iVideoPlayControllerCustomCommands.Play(aStartTime, aEndTime);
   1.565 +	if (err != KErrNone)
   1.566 +	    {
   1.567 +	    iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
   1.568 +		DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play (exit1)-- - Err %d", err);
   1.569 +	    return;
   1.570 +	    }
   1.571 +	iState = EPlaying;
   1.572 +	//If Audio Resource Notification request is pending - attempt now
   1.573 +	if(iArnEventHolder != KNullUid)
   1.574 +		{
   1.575 +		err = iNotificationRegistrationCommands.RegisterAsClient(iArnEventHolder, iNotificationDataHolder);			
   1.576 +		iArnEventHolder = KNullUid;
   1.577 +		iNotificationDataHolder = KNullDesC8;
   1.578 +		if(err != KErrNone)
   1.579 +			{
   1.580 +			iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
   1.581 +			}
   1.582 +		}
   1.583 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play-- - Err %d", err);
   1.584 +	}
   1.585 +
   1.586 +
   1.587 +TInt CVideoPlayerUtility::CBody::Stop()
   1.588 +	{
   1.589 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Stop++");
   1.590 +	TInt err = iController.Stop();
   1.591 +	iState = EStopped;
   1.592 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Stop-- - Err %d", err);
   1.593 +	return err;
   1.594 +	}
   1.595 +
   1.596 +void CVideoPlayerUtility::CBody::PauseL()
   1.597 +	{
   1.598 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PauseL++");
   1.599 +	User::LeaveIfError(iController.Pause());
   1.600 +	iState = EPaused;
   1.601 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PauseL--");
   1.602 +	}
   1.603 +
   1.604 +void CVideoPlayerUtility::CBody::SetVolumeL(TInt aVolume)
   1.605 +	{
   1.606 +	User::LeaveIfError(iAudioPlayDeviceCustomCommands.SetVolume(aVolume));
   1.607 +	}
   1.608 +
   1.609 +void CVideoPlayerUtility::CBody::PrepareDSAL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow)
   1.610 +	{
   1.611 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL++");
   1.612 +	CDirectScreenAccess* old = iDirectScreenAccess;
   1.613 +	iDirectScreenAccess = CDirectScreenAccess::NewL(aWs,aScreenDevice,aWindow,*this);
   1.614 +	delete old;
   1.615 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL - Starting");
   1.616 +	iDirectScreenAccess->StartL();
   1.617 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL--");
   1.618 +	}
   1.619 +
   1.620 +void CVideoPlayerUtility::CBody::SetDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice,
   1.621 +							RWindowBase& aWindow, const TRect& aWindowRect,
   1.622 +							const TRect& aClipRect)
   1.623 +	{	
   1.624 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetDisplayWindowL++");
   1.625 +    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
   1.626 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
   1.627 +    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);
   1.628 +    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindowRect %d,%d - %d,%d", aWindowRect.iTl.iX, aWindowRect.iTl.iY, aWindowRect.iBr.iX, aWindowRect.iBr.iY);
   1.629 +    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aClipRect %d,%d - %d,%d", aClipRect.iTl.iX, aClipRect.iTl.iY, aClipRect.iBr.iX, aClipRect.iBr.iY);
   1.630 +
   1.631 +    iWindowRect = aWindowRect;
   1.632 +	iClipRect = aClipRect;
   1.633 +	
   1.634 +#ifdef SYMBIAN_BUILD_GCE
   1.635 +	// If called from CVideoPlayerUtility2, fail with KErrNotSupport. Otherwise, if the controller supports 
   1.636 +	// the graphics surfaces, it will render to graphics surfaces. If the controller doesn't support 
   1.637 +	// the graphics surfaces, it will use direct screen access.
   1.638 +	if (iUsingVPU2)
   1.639 +		{
   1.640 +		User::Leave(KErrNotSupported);
   1.641 +		}
   1.642 +	// If the controller does not support GCE or the source has not been opened, start new DSA.
   1.643 +	if (!iGraphicsSurfaceSupported)
   1.644 +		{
   1.645 +		PrepareDSAL(aWs, aScreenDevice, aWindow);
   1.646 +		}
   1.647 +
   1.648 +	if (!iGraphicsSurfaceSupported && iControllerOpen)
   1.649 +		{
   1.650 +		// Set display window and update region, if controller is open
   1.651 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect,iClipRect));
   1.652 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion()));
   1.653 +		}
   1.654 +		
   1.655 +	if (iGraphicsSurfaceSupported && iControllerOpen)
   1.656 +		{
   1.657 +		// When the controller supports graphics surfaces, need to stop direct screen access.
   1.658 + 		if (iDirectScreenAccess)
   1.659 + 			{
   1.660 + 			iDirectScreenAccess->Cancel();
   1.661 +  			AbortNow(RDirectScreenAccess::ETerminateCancel);
   1.662 + 			}
   1.663 +		
   1.664 +		// When using surfaces for CVPU we use DoAddDisplayWindowL() which requires clip rectangle and video extent
   1.665 +		// as arguments. Video extent is not supported by CVPU so aWindowRect is used instead. This function
   1.666 +		// assumes these args are relative to the window. However they are relative to the display and must be
   1.667 +		// converted.
   1.668 +		TRect windowRectRelativeToWindow;
   1.669 +		TRect clipRectRelativeToWindow;		
   1.670 +		ConvertFromRelativeToDisplayToRelativeToWindow(aWindow, aWindowRect, aClipRect, windowRectRelativeToWindow, clipRectRelativeToWindow);
   1.671 +
   1.672 +		// check if display for window already exists and if so do an update else create a new display
   1.673 +		TRAPD(err, CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
   1.674 +		if (err == KErrNone)
   1.675 +		    {
   1.676 +		    DoUpdateDisplayWindowL(aWs, aWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL);
   1.677 +		    }
   1.678 +		else
   1.679 +		    {
   1.680 +		    DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL);
   1.681 +		    }
   1.682 +		}
   1.683 +#else
   1.684 +	PrepareDSAL(aWs, aScreenDevice, aWindow);
   1.685 +	
   1.686 +	if (iControllerOpen)
   1.687 +		{
   1.688 +		// Set display window and update region, if controller is open
   1.689 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect,iClipRect));
   1.690 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion()));
   1.691 +		if(iDirectScreenAccessAbort)
   1.692 +			{
   1.693 +			User::LeaveIfError(iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EResumeDSA));
   1.694 +			iDirectScreenAccessAbort = EFalse;
   1.695 +			}
   1.696 +		}
   1.697 +#endif
   1.698 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetDisplayWindowL--");
   1.699 +	}
   1.700 +
   1.701 +TReal32 CVideoPlayerUtility::CBody::VideoFrameRateL() const
   1.702 +	{
   1.703 +	TReal32 framerate = 0;
   1.704 +	User::LeaveIfError(iVideoControllerCustomCommands.GetFrameRate(framerate));
   1.705 +	return framerate;
   1.706 +	}
   1.707 +
   1.708 +
   1.709 +void CVideoPlayerUtility::CBody::VideoFrameSizeL(TSize& aSize) const
   1.710 +	{
   1.711 +	User::LeaveIfError(iVideoControllerCustomCommands.GetVideoFrameSize(aSize));
   1.712 +	}
   1.713 +
   1.714 +TInt CVideoPlayerUtility::CBody::Volume() const
   1.715 +	{
   1.716 +	TInt vol = 0;
   1.717 +	iAudioPlayDeviceCustomCommands.GetVolume(vol);
   1.718 +	return vol;
   1.719 +	}
   1.720 +
   1.721 +
   1.722 +void CVideoPlayerUtility::CBody::SetBalanceL(TInt aBalance)
   1.723 +	{
   1.724 +	User::LeaveIfError(iAudioPlayDeviceCustomCommands.SetBalance(aBalance));
   1.725 +	}
   1.726 +
   1.727 +
   1.728 +TInt CVideoPlayerUtility::CBody::Balance() const
   1.729 +	{
   1.730 +	TInt bal = 0;
   1.731 +	iAudioPlayDeviceCustomCommands.GetBalance(bal);
   1.732 +	return bal;
   1.733 +	}
   1.734 +
   1.735 +void CVideoPlayerUtility::CBody::SetRotationL(TVideoRotation aRotation)
   1.736 +	{
   1.737 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL++");
   1.738 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aRotation %d", aRotation);
   1.739 +
   1.740 +#ifdef SYMBIAN_BUILD_GCE
   1.741 +	if (!iGraphicsSurfaceSupported)
   1.742 +		{
   1.743 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetRotation(aRotation));
   1.744 +		}
   1.745 +	else
   1.746 +		{
   1.747 +		// Rotation setting is not sent to controller when graphics surfaces are used.
   1.748 +		// If the surface has been created, perform rotation with the help of graphics surfaces;
   1.749 +		// otherwise, just store the rotation info.
   1.750 +
   1.751 +		TInt count = iActiveDisplays.Count();
   1.752 +		
   1.753 +		for (TInt i = 0; i < count; ++i)
   1.754 +			{
   1.755 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   1.756 +			CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
   1.757 +			RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
   1.758 +			TInt windowcount = windows.Count();	
   1.759 +			for (TInt i = 0; i < windowcount; ++i)
   1.760 +				{
   1.761 +				CMediaClientVideoDisplayBody::TWindowData& window = windows[i];		
   1.762 +				if (window.iRotation != aRotation)
   1.763 +					{
   1.764 +					// update config only if setting has actually changed
   1.765 +					display->SetRotationL(*window.iWindow, aRotation, iCropRegion);
   1.766 +
   1.767 +					if (iSubtitleUtility)
   1.768 +						{
   1.769 +						TMMFSubtitleWindowConfig config;
   1.770 +						GetSubtitleConfigFromWindowData(window, config);
   1.771 +
   1.772 +						iSubtitleUtility->UpdateSubtitleConfig(config);
   1.773 +						}
   1.774 +					}
   1.775 +				}
   1.776 +#else
   1.777 +
   1.778 +			iActiveDisplays[i]->SetRotationL(aRotation, iCropRegion);
   1.779 +#endif//SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
   1.780 +			}
   1.781 +
   1.782 +		iGlobalRotation = aRotation;
   1.783 +
   1.784 +		}
   1.785 +#else 
   1.786 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.SetRotation(aRotation));
   1.787 +#endif // SYMBIAN_BUILD_GCE
   1.788 +
   1.789 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL--");
   1.790 +	}
   1.791 +
   1.792 +TVideoRotation CVideoPlayerUtility::CBody::RotationL() const
   1.793 +	{
   1.794 +	TVideoRotation rot = EVideoRotationNone;
   1.795 +#ifdef SYMBIAN_BUILD_GCE
   1.796 +	if (!iGraphicsSurfaceSupported)
   1.797 +		{		
   1.798 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.GetRotation(rot));		
   1.799 +		}
   1.800 +	else 
   1.801 +		{
   1.802 +		// Rotation setting is not retrieved from controller when graphics surfaces are used.
   1.803 +		rot = iGlobalRotation;
   1.804 +		}
   1.805 +#else
   1.806 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetRotation(rot));
   1.807 +#endif // SYMBIAN_BUILD_GCE
   1.808 +	return rot;
   1.809 +	}
   1.810 +
   1.811 +void CVideoPlayerUtility::CBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, TBool aAntiAliasFiltering)
   1.812 +	{
   1.813 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL");
   1.814 +    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f, aAntiAliasFiltering %d", aWidthPercentage, aHeightPercentage, aAntiAliasFiltering);
   1.815 +
   1.816 +#ifdef SYMBIAN_BUILD_GCE
   1.817 +	if (!iGraphicsSurfaceSupported)
   1.818 +		{
   1.819 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
   1.820 +		}
   1.821 +	else
   1.822 +		{
   1.823 +		// Scale factor  setting is not sent to controller when graphics surfaces are used.
   1.824 +		// If the surface has been created, perform scale factor with the help of graphics surfaces.
   1.825 +		iAntiAliasFiltering = aAntiAliasFiltering;
   1.826 +		iGlobalScaleWidth = aWidthPercentage;
   1.827 +		iGlobalScaleHeight = aHeightPercentage;
   1.828 +		iGlobalAutoScaleType = EAutoScaleNone;
   1.829 +
   1.830 +		TInt count = iActiveDisplays.Count();
   1.831 +		
   1.832 +		for (TInt i = 0; i < count; ++i)
   1.833 +			{
   1.834 +			iActiveDisplays[i]->SetScaleFactorL(aWidthPercentage, aHeightPercentage, iCropRegion);
   1.835 +			}
   1.836 +		}
   1.837 +#else
   1.838 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.SetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
   1.839 +#endif	// SYMBIAN_BUILD_GCE
   1.840 +
   1.841 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL--");
   1.842 +	}
   1.843 +
   1.844 +void CVideoPlayerUtility::CBody::GetScaleFactorL(TReal32& aWidthPercentage, TReal32& aHeightPercentage, TBool& aAntiAliasFiltering) const
   1.845 +	{
   1.846 +#ifdef SYMBIAN_BUILD_GCE
   1.847 +	if (!iGraphicsSurfaceSupported)
   1.848 +		{
   1.849 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.GetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
   1.850 +		}
   1.851 +	else
   1.852 +		{
   1.853 +		// Scale factor setting is not retrieved from controller when graphics surfaces are used.
   1.854 +		
   1.855 +		aWidthPercentage = iGlobalScaleWidth;
   1.856 +		aHeightPercentage = iGlobalScaleHeight;	
   1.857 +		
   1.858 +		aAntiAliasFiltering = iAntiAliasFiltering;
   1.859 +		}
   1.860 +#else
   1.861 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));	
   1.862 +#endif // SYMBIAN_BUILD_GCE
   1.863 +	}
   1.864 +
   1.865 +void CVideoPlayerUtility::CBody::SetCropRegionL(const TRect& aCropRegion)
   1.866 +	{
   1.867 +#ifdef SYMBIAN_BUILD_GCE
   1.868 +	if (!iGraphicsSurfaceSupported)
   1.869 +		{
   1.870 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetCropRegion(aCropRegion));
   1.871 +		}
   1.872 +	else
   1.873 +		{
   1.874 +		// Crop region setting is not sent to controller when graphics surfaces are used.
   1.875 +		// If the surface has been created, perform crop region with the help of graphics surfaces;
   1.876 +		// otherwise, just store the crop region info.
   1.877 +		if (aCropRegion != iCropRegion)
   1.878 +			{
   1.879 +			iCropRegion = aCropRegion;
   1.880 +			User::LeaveIfError(SetAllBackgroundSurfaces());
   1.881 +			}
   1.882 +		}
   1.883 +#else
   1.884 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.SetCropRegion(aCropRegion));
   1.885 +#endif // SYMBIAN_BUILD_GCE
   1.886 +	}
   1.887 +
   1.888 +void CVideoPlayerUtility::CBody::GetCropRegionL(TRect& aCropRegion) const
   1.889 +	{
   1.890 +#ifdef SYMBIAN_BUILD_GCE
   1.891 +	if (!iGraphicsSurfaceSupported )
   1.892 +		{
   1.893 +		User::LeaveIfError(iVideoPlayControllerCustomCommands.GetCropRegion(aCropRegion));
   1.894 +		}
   1.895 +	else
   1.896 +		{
   1.897 +		// Crop rectangle setting is not retrieved from controller when graphics surfaces are used.
   1.898 +		aCropRegion = iCropRegion;
   1.899 +		}
   1.900 +#else
   1.901 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetCropRegion(aCropRegion));
   1.902 +#endif // SYMBIAN_BUILD_GCE
   1.903 +	}
   1.904 +
   1.905 +void CVideoPlayerUtility::CBody::Prepare()
   1.906 +	{
   1.907 +	TInt error = iVideoPlayControllerCustomCommands.Prepare();
   1.908 +	if (error)
   1.909 +		iObserver.MvpuoPrepareComplete(error);
   1.910 +	}
   1.911 +
   1.912 +const TDesC8& CVideoPlayerUtility::CBody::VideoFormatMimeType() const
   1.913 +	{
   1.914 +	TPtr8 des = iMimeType->Des();
   1.915 +	TInt err = iVideoControllerCustomCommands.GetVideoMimeType(des);
   1.916 +	if (!err)
   1.917 +		return *iMimeType;
   1.918 +	else
   1.919 +		return KNullDesC8;
   1.920 +	}
   1.921 +											 
   1.922 +void CVideoPlayerUtility::CBody::RegisterForVideoLoadingNotification(MVideoLoadingObserver& aObserver)
   1.923 +	{
   1.924 +	iVideoLoadingObserver = &aObserver;
   1.925 +	}
   1.926 +
   1.927 +TInt CVideoPlayerUtility::CBody::NumberOfMetaDataEntriesL() const
   1.928 +	{
   1.929 +	TInt num = 0;
   1.930 +	User::LeaveIfError(iController.GetNumberOfMetaDataEntries(num));
   1.931 +	return num;
   1.932 +	}
   1.933 +
   1.934 +
   1.935 +CMMFMetaDataEntry* CVideoPlayerUtility::CBody::MetaDataEntryL(TInt aMetaDataIndex) const
   1.936 +	{
   1.937 +	return iController.GetMetaDataEntryL(aMetaDataIndex);
   1.938 +	}
   1.939 +
   1.940 +void CVideoPlayerUtility::CBody::SetPriorityL(TInt aPriority, TInt aPref)
   1.941 +	{
   1.942 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPriorityL++");
   1.943 +    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::SetPriorityL - aPriority %d, aPref %d", aPriority, aPref);
   1.944 +
   1.945 +    iPrioritySettings.iPref = aPref;
   1.946 +	iPrioritySettings.iPriority = aPriority;
   1.947 +
   1.948 +	TInt err = iController.SetPrioritySettings(iPrioritySettings);
   1.949 +	if ((err == KErrNone) || (err == KErrNotReady))
   1.950 +		{
   1.951 +		iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
   1.952 +		}
   1.953 +	else
   1.954 +		{
   1.955 +		User::Leave(err);
   1.956 +		}
   1.957 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPriorityL--");
   1.958 +	}
   1.959 +
   1.960 +void CVideoPlayerUtility::CBody::PriorityL(TInt & aPriority, TMdaPriorityPreference &aPref) const 
   1.961 +	{
   1.962 +	aPriority = iPrioritySettings.iPriority;
   1.963 +	aPref = TMdaPriorityPreference(iPrioritySettings.iPref);
   1.964 +	}
   1.965 +
   1.966 +
   1.967 +void CVideoPlayerUtility::CBody::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
   1.968 +	{
   1.969 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPositionL++");
   1.970 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetPositionL - aPosition %ld", aPosition.Int64());
   1.971 +	User::LeaveIfError(iController.SetPosition(aPosition));
   1.972 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPositionL--");
   1.973 +	}
   1.974 +
   1.975 +
   1.976 +TTimeIntervalMicroSeconds CVideoPlayerUtility::CBody::DurationL() const
   1.977 +	{
   1.978 +	TTimeIntervalMicroSeconds duration;
   1.979 +	User::LeaveIfError(iController.GetDuration(duration));
   1.980 +	return duration;
   1.981 +	}
   1.982 +
   1.983 +TTimeIntervalMicroSeconds CVideoPlayerUtility::CBody::PositionL() const
   1.984 +	{
   1.985 +	TTimeIntervalMicroSeconds position;
   1.986 +	User::LeaveIfError(iController.GetPosition(position));
   1.987 +	return position;
   1.988 +	}
   1.989 +
   1.990 +TInt CVideoPlayerUtility::CBody::MaxVolume() const
   1.991 +	{
   1.992 +	TInt maxVol = 0;
   1.993 +	iAudioPlayDeviceCustomCommands.GetMaxVolume(maxVol);
   1.994 +	return maxVol;
   1.995 +	}
   1.996 +
   1.997 +void CVideoPlayerUtility::CBody::GetFrameL(TDisplayMode aDisplayMode, TBool aUseIntentAPI, TIntent aIntent)
   1.998 +	{
   1.999 +	delete iFrameBitmap;
  1.1000 +	iFrameBitmap = NULL;
  1.1001 +	iFrameBitmap = new (ELeave) CFbsBitmap;
  1.1002 +	User::LeaveIfError(iFrameBitmap->Create(TSize(0,0),aDisplayMode));
  1.1003 +
  1.1004 +	iFrameCallback->SetFrame(*iFrameBitmap);
  1.1005 +
  1.1006 +	if (aUseIntentAPI)
  1.1007 +		{
  1.1008 +		iVideoDRMExtCustomCommands.GetFrame(*iFrameBitmap, aIntent, iFrameCallback->ActiveStatus());
  1.1009 +		}
  1.1010 +	else
  1.1011 +		{
  1.1012 +		iVideoPlayControllerCustomCommands.GetFrame(*iFrameBitmap, iFrameCallback->ActiveStatus());
  1.1013 +		}
  1.1014 +	}
  1.1015 +
  1.1016 +MMMFDRMCustomCommand* CVideoPlayerUtility::CBody::GetDRMCustomCommand()
  1.1017 +	{
  1.1018 +	// XXX: check controller supports MMMFDRMCustomCommandImplementor
  1.1019 +	TInt error = iDRMCustomCommands.EvaluateIntent(ContentAccess::EPeek);
  1.1020 +	if (error==KErrNone)
  1.1021 +		{
  1.1022 +		return static_cast<MMMFDRMCustomCommand*>(&iDRMCustomCommands);
  1.1023 +		}
  1.1024 +	else
  1.1025 +		{
  1.1026 +		return NULL;
  1.1027 +		}
  1.1028 +	}
  1.1029 +	
  1.1030 +TInt CVideoPlayerUtility::CBody::VideoBitRateL() const
  1.1031 +	{
  1.1032 +	TInt bitRate;
  1.1033 +	User::LeaveIfError(iVideoControllerCustomCommands.GetVideoBitRate(bitRate));
  1.1034 +	return bitRate;
  1.1035 +	}
  1.1036 +
  1.1037 +TInt CVideoPlayerUtility::CBody::AudioBitRateL() const
  1.1038 +	{
  1.1039 +	TInt bitRate;
  1.1040 +	User::LeaveIfError(iVideoControllerCustomCommands.GetAudioBitRate(bitRate));
  1.1041 +	return bitRate;
  1.1042 +	}
  1.1043 +
  1.1044 +TBool CVideoPlayerUtility::CBody::AudioEnabledL() const
  1.1045 +	{
  1.1046 +	TBool enabled;
  1.1047 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetAudioEnabled(enabled));
  1.1048 +	return enabled;
  1.1049 +	}
  1.1050 +	
  1.1051 +	
  1.1052 +void CVideoPlayerUtility::CBody::RefreshFrameL()
  1.1053 +	{
  1.1054 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.RefreshFrame());
  1.1055 +	}
  1.1056 +
  1.1057 +TFourCC CVideoPlayerUtility::CBody::AudioTypeL() const
  1.1058 +	{
  1.1059 +	TFourCC codec;
  1.1060 +	User::LeaveIfError(iVideoControllerCustomCommands.GetAudioCodec(codec));
  1.1061 +	return codec;
  1.1062 +	}
  1.1063 +
  1.1064 +
  1.1065 +void CVideoPlayerUtility::CBody::HandleEvent(const TMMFEvent& aEvent)
  1.1066 +	{
  1.1067 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::HandleEvent++");
  1.1068 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::HandleEvent - Event type 0x%X", aEvent.iEventType);
  1.1069 +
  1.1070 +    if (aEvent.iEventType == KMMFEventCategoryVideoOpenComplete)
  1.1071 +		{
  1.1072 +		// if we haven't had a MfaocComplete() callback yet,
  1.1073 +		// we need to delay the call back to the client
  1.1074 +		// because the source/sink will not have been opened yet.
  1.1075 +		iEventOpenReceived = ETrue;
  1.1076 +		if (iOpenError == KErrNone)
  1.1077 +			iOpenError = aEvent.iErrorCode;
  1.1078 +		if (iCallbackOpenReceived)
  1.1079 +			iObserver.MvpuoOpenComplete(aEvent.iErrorCode);
  1.1080 +		}
  1.1081 +	else if (aEvent.iEventType == KMMFEventCategoryVideoPrepareComplete)
  1.1082 +		{
  1.1083 +		iObserver.MvpuoPrepareComplete(aEvent.iErrorCode);
  1.1084 +		}
  1.1085 +	else if (aEvent.iEventType == KMMFEventCategoryPlaybackComplete)
  1.1086 +		{
  1.1087 +		iObserver.MvpuoPlayComplete(aEvent.iErrorCode);
  1.1088 +		}
  1.1089 +	else if (aEvent.iEventType == KMMFEventCategoryVideoLoadingStarted)
  1.1090 +		{
  1.1091 +		if (iVideoLoadingObserver)
  1.1092 +			iVideoLoadingObserver->MvloLoadingStarted();
  1.1093 +		}
  1.1094 +	else if (aEvent.iEventType == KMMFEventCategoryVideoLoadingComplete)
  1.1095 +		{
  1.1096 +		if (iVideoLoadingObserver)
  1.1097 +			iVideoLoadingObserver->MvloLoadingComplete();
  1.1098 +		}
  1.1099 +	else if(aEvent.iEventType == KMMFEventCategoryAudioResourceAvailable)
  1.1100 +		{
  1.1101 +		if(iAudioResourceNotificationCallBack != NULL)
  1.1102 +			{
  1.1103 +			TBuf8<TMMFAudioConfig::KNotificationDataBufferSize> notificationData;
  1.1104 +			if (KErrNone != iNotificationRegistrationCommands.GetResourceNotificationData(aEvent.iEventType, notificationData))
  1.1105 +				{
  1.1106 +				notificationData.SetLength(0);
  1.1107 +				}
  1.1108 +			iAudioResourceNotificationCallBack->MarncResourceAvailable(aEvent.iEventType, notificationData);	
  1.1109 +			}
  1.1110 +		}
  1.1111 +#ifdef SYMBIAN_BUILD_GCE
  1.1112 +	else if(aEvent.iEventType == KMMFEventCategoryVideoSurfaceCreated)
  1.1113 +		{
  1.1114 +		TInt error = SurfaceCreated();
  1.1115 +			
  1.1116 +		if (error != KErrNone)	
  1.1117 +			{
  1.1118 +			// Send error to the client
  1.1119 +			TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
  1.1120 +			iObserver.MvpuoEvent(generalError);	
  1.1121 +			}
  1.1122 +		}
  1.1123 +	else if(aEvent.iEventType == KMMFEventCategoryVideoSurfaceParametersChanged)
  1.1124 +		{
  1.1125 +		TInt error = SurfaceParametersChanged();
  1.1126 +				
  1.1127 +		if (error != KErrNone)	
  1.1128 +			{
  1.1129 +			// Send error to the client
  1.1130 +			TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
  1.1131 +			iObserver.MvpuoEvent(generalError);	
  1.1132 +			}
  1.1133 +		}		
  1.1134 +	else if(aEvent.iEventType == KMMFEventCategoryVideoRemoveSurface)
  1.1135 +		{
  1.1136 +		// Check surface is created
  1.1137 +		TInt error = RemoveSurface(ETrue);
  1.1138 +			
  1.1139 +		if (error != KErrNone)
  1.1140 +			{
  1.1141 +			// Send error to the client
  1.1142 +			TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
  1.1143 +			iObserver.MvpuoEvent(generalError);	
  1.1144 +			}
  1.1145 +		}
  1.1146 +#endif // SYMBIAN_BUILD_GCE	
  1.1147 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1148 +	else if(aEvent.iEventType == KMMFEventCategoryVideoSubtitleCrpReady)
  1.1149 +		{
  1.1150 +		if (iSubtitleUtility)
  1.1151 +			{
  1.1152 +			// subtitle has not been disabled before event arrive
  1.1153 +			RWindow* window = FindWindowWithWsHandle(iActiveDisplays, aEvent.iErrorCode);
  1.1154 +			if (window)
  1.1155 +				{
  1.1156 +				// window has not been removed before event arrive
  1.1157 +				iSubtitleUtility->HandleCrpReady(*window);
  1.1158 +				}
  1.1159 +			}
  1.1160 +		}
  1.1161 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1162 +	else 
  1.1163 +		// Pass on all unrecognised events to the client
  1.1164 +		iObserver.MvpuoEvent(aEvent);
  1.1165 +
  1.1166 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::HandleEvent--");
  1.1167 +	}
  1.1168 +
  1.1169 +#ifdef SYMBIAN_BUILD_GCE
  1.1170 +TInt CVideoPlayerUtility::CBody::SurfaceCreated()
  1.1171 +	{
  1.1172 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceCreated++");
  1.1173 +
  1.1174 +    TInt count = iActiveDisplays.Count();
  1.1175 +	TBool replaceSurface = !(iSurfaceId.IsNull());
  1.1176 +	TSurfaceId oldSurfaceId(iSurfaceId);
  1.1177 +	
  1.1178 +	// first remove surface if one already in use
  1.1179 +	if(replaceSurface)
  1.1180 +		{
  1.1181 +		for (TInt i = 0; i < count; i++)
  1.1182 +			{
  1.1183 +			CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
  1.1184 +			display->RemoveSurface(EFalse);
  1.1185 +			}
  1.1186 +		iSurfaceId = TSurfaceId::CreateNullId();
  1.1187 +		}
  1.1188 +	
  1.1189 +	TSurfaceId surfaceId;
  1.1190 +	TRect cropRect;
  1.1191 +	TVideoAspectRatio aspectRatio;
  1.1192 +	
  1.1193 +	TInt error = iVideoPlaySurfaceSupportCustomCommands.GetSurfaceParameters(surfaceId, 
  1.1194 +										cropRect, 
  1.1195 +										aspectRatio);
  1.1196 +	if(error != KErrNone)
  1.1197 +		{
  1.1198 +		if(replaceSurface)
  1.1199 +				{
  1.1200 +				// ignore error
  1.1201 +				iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(oldSurfaceId);
  1.1202 +				}
  1.1203 +		return error;
  1.1204 +		}
  1.1205 +	
  1.1206 +	// loop through all displays, if any fail continue and report error later
  1.1207 +	TInt error2;
  1.1208 +	for (TInt i = 0; i < count; ++i)
  1.1209 +		{
  1.1210 +		error2 = iActiveDisplays[i]->SurfaceCreated(surfaceId, cropRect, aspectRatio, iCropRegion);
  1.1211 +		if(error2 != KErrNone)
  1.1212 +			{
  1.1213 +			error = error2;
  1.1214 +			}
  1.1215 +		}
  1.1216 +	
  1.1217 +	// now store surface details
  1.1218 +	iSurfaceId = surfaceId;
  1.1219 +	iSurfaceCropRect = cropRect;
  1.1220 +	iAspectRatio = aspectRatio;
  1.1221 +	
  1.1222 +	// if surface already existed tell video adaptation it is no longer in use. Video adaptation
  1.1223 +	// will remove the surface when it receives this call therefore the following code must be done at the
  1.1224 +	// end of this function.
  1.1225 +	if (replaceSurface)
  1.1226 +        {
  1.1227 +        error2 = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(oldSurfaceId);
  1.1228 +        if (error2 != KErrNone)
  1.1229 +            {
  1.1230 +            error = error2;
  1.1231 +            }
  1.1232 +        }
  1.1233 +
  1.1234 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceCreated--");
  1.1235 +	return error;
  1.1236 +	}
  1.1237 +
  1.1238 +TInt CVideoPlayerUtility::CBody::SurfaceParametersChanged()
  1.1239 +	{
  1.1240 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceParametersChanged++");
  1.1241 +	if (iSurfaceId.IsNull())
  1.1242 +		{
  1.1243 +		return KErrNotSupported;
  1.1244 +		}
  1.1245 +	
  1.1246 +	TSurfaceId surfaceId;
  1.1247 +	TRect cropRect;
  1.1248 +	TVideoAspectRatio aspectRatio;
  1.1249 +	
  1.1250 +	TInt error = iVideoPlaySurfaceSupportCustomCommands.GetSurfaceParameters(surfaceId, 
  1.1251 +										cropRect, 
  1.1252 +										aspectRatio);
  1.1253 +	if (error != KErrNone)
  1.1254 +		{
  1.1255 +		return error;
  1.1256 +		}
  1.1257 +	
  1.1258 +	if (iSurfaceId != surfaceId)
  1.1259 +		{
  1.1260 +		return KErrInUse;
  1.1261 +		}
  1.1262 +
  1.1263 +	TInt count = iActiveDisplays.Count();
  1.1264 +	TInt error2 = KErrNone;
  1.1265 +	for (TInt i = 0; i < count; ++i)
  1.1266 +		{
  1.1267 +		error2 = iActiveDisplays[i]->SurfaceParametersChanged(surfaceId, cropRect, aspectRatio);
  1.1268 +		
  1.1269 +		// Save the error for the first failure only
  1.1270 +		if ((error2 != KErrNone) && (error == KErrNone))
  1.1271 +			{
  1.1272 +			error = error2;
  1.1273 +			}
  1.1274 +		}
  1.1275 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SurfaceParametersChanged-- - Error %d", error);
  1.1276 +    return error;
  1.1277 +	}
  1.1278 +		
  1.1279 +TInt CVideoPlayerUtility::CBody::SetAllBackgroundSurfaces()
  1.1280 +	{
  1.1281 +	TInt count = iActiveDisplays.Count();
  1.1282 +	TInt err = KErrNone;
  1.1283 +	
  1.1284 +	for (TInt i = 0; i < count; ++i)
  1.1285 +		{
  1.1286 +		CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
  1.1287 +		err = display->RedrawWindows(iCropRegion);
  1.1288 +			
  1.1289 +		if (err != KErrNone)
  1.1290 +			{
  1.1291 +			break;
  1.1292 +			}
  1.1293 +		}
  1.1294 +	return err;
  1.1295 +	}
  1.1296 +
  1.1297 +TInt CVideoPlayerUtility::CBody::RemoveSurface(TBool aControllerEvent)
  1.1298 +	{
  1.1299 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveSurface++");
  1.1300 +	if (iSurfaceId.IsNull())
  1.1301 +		{
  1.1302 +		return KErrNotFound;
  1.1303 +		}
  1.1304 +	
  1.1305 +	TInt count = iActiveDisplays.Count();
  1.1306 +	for (TInt i = 0; i < count; i++)
  1.1307 +		{
  1.1308 +		iActiveDisplays[i]->RemoveSurface(aControllerEvent);
  1.1309 +		}
  1.1310 +	
  1.1311 +	TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iSurfaceId);
  1.1312 +
  1.1313 +	iSurfaceId = TSurfaceId::CreateNullId();
  1.1314 +	
  1.1315 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveSurface-- - Error %d", error);
  1.1316 +	return error;
  1.1317 +	}
  1.1318 +	
  1.1319 +#endif // SYMBIAN_BUILD_GCE
  1.1320 +
  1.1321 +void CVideoPlayerUtility::CBody::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
  1.1322 +	{
  1.1323 +	if (iControllerOpen)
  1.1324 +		{
  1.1325 +		iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EAbortDSA);
  1.1326 +		iDirectScreenAccessAbort = ETrue;
  1.1327 +		}
  1.1328 +	}
  1.1329 +
  1.1330 +void CVideoPlayerUtility::CBody::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/) 
  1.1331 +	{
  1.1332 +	__ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument)); // should always be valid if we have a callback from it
  1.1333 +	TRAPD( err, iDirectScreenAccess->StartL());
  1.1334 +
  1.1335 +	if (iControllerOpen)
  1.1336 +		{
  1.1337 +		if (err == KErrNone)
  1.1338 +			{
  1.1339 +			iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion());
  1.1340 +			iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EResumeDSA);
  1.1341 +			}
  1.1342 +		}
  1.1343 +	}
  1.1344 +
  1.1345 +TInt CVideoPlayerUtility::CBody::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom)
  1.1346 +	{
  1.1347 +	return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom);
  1.1348 +	}
  1.1349 +	
  1.1350 +TInt CVideoPlayerUtility::CBody::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2)
  1.1351 +	{
  1.1352 +	return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2);
  1.1353 +	}
  1.1354 +	
  1.1355 +void CVideoPlayerUtility::CBody::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus)
  1.1356 +	{
  1.1357 +	iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom, aStatus);
  1.1358 +	}
  1.1359 +	
  1.1360 +void CVideoPlayerUtility::CBody::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus)
  1.1361 +	{
  1.1362 +	iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aStatus);
  1.1363 +	}
  1.1364 +	
  1.1365 +void CVideoPlayerUtility::CBody::SetVideoFrameRateL(TReal32 aFramesPerSecond)
  1.1366 +	{
  1.1367 +	User::LeaveIfError(iVideoControllerCustomCommands.SetFrameRate(aFramesPerSecond));
  1.1368 +	}
  1.1369 +
  1.1370 +const CMMFControllerImplementationInformation& CVideoPlayerUtility::CBody::ControllerImplementationInformationL()
  1.1371 +	{
  1.1372 +	if (!iControllerImplementationInformation)
  1.1373 +		{
  1.1374 +		if (iControllerUid==KNullUid)
  1.1375 +			User::Leave(KErrNotReady);
  1.1376 +		iControllerImplementationInformation = CMMFControllerImplementationInformation::NewL(iControllerUid);
  1.1377 +		}
  1.1378 +	return *iControllerImplementationInformation;
  1.1379 +	}
  1.1380 +	
  1.1381 +void CVideoPlayerUtility::CBody::GetVideoLoadingProgressL(TInt& aPercentageProgress)
  1.1382 +	{
  1.1383 +	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetLoadingProgress(aPercentageProgress));
  1.1384 +	}
  1.1385 +
  1.1386 +void CVideoPlayerUtility::CBody::StopDirectScreenAccessL()
  1.1387 +	{
  1.1388 +#ifdef SYMBIAN_BUILD_GCE
  1.1389 +	if (iUsingVPU2)
  1.1390 +		{
  1.1391 +		User::Leave(KErrNotSupported);
  1.1392 +		}
  1.1393 +
  1.1394 +	if (!iGraphicsSurfaceSupported)
  1.1395 +		{
  1.1396 +		__ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument));
  1.1397 +		iDirectScreenAccess->Cancel();
  1.1398 +		AbortNow(RDirectScreenAccess::ETerminateCancel);
  1.1399 +		}
  1.1400 +#else
  1.1401 +	__ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument));
  1.1402 +	iDirectScreenAccess->Cancel();
  1.1403 +	AbortNow(RDirectScreenAccess::ETerminateCancel);
  1.1404 +#endif // SYMBIAN_BUILD_GCE
  1.1405 +	}
  1.1406 +	
  1.1407 +void CVideoPlayerUtility::CBody::StartDirectScreenAccessL()
  1.1408 +	{
  1.1409 +#ifdef SYMBIAN_BUILD_GCE
  1.1410 +	if (iUsingVPU2)
  1.1411 +		{
  1.1412 +		User::Leave(KErrNotSupported);
  1.1413 +		}
  1.1414 +
  1.1415 +	if (!iGraphicsSurfaceSupported)
  1.1416 +		{
  1.1417 +		// ETerminateCancel is a dummy value that is ignored by Restart()
  1.1418 +		Restart(RDirectScreenAccess::ETerminateCancel);
  1.1419 +		}
  1.1420 +#else
  1.1421 +	// ETerminateCancel is a dummy value that is ignored by Restart()
  1.1422 +	Restart(RDirectScreenAccess::ETerminateCancel);
  1.1423 +#endif  // SYMBIAN_BUILD_GCE
  1.1424 +	}
  1.1425 +
  1.1426 +//registers for notification when audio resource is available.
  1.1427 +TInt CVideoPlayerUtility::CBody::RegisterAudioResourceNotification( MMMFAudioResourceNotificationCallback& aCallback, 
  1.1428 +																	TUid aNotificationEventUid, 
  1.1429 +																	const TDesC8& aNotificationRegistrationData)
  1.1430 +	{
  1.1431 +	//if not valid notification event id, return;
  1.1432 +	if(aNotificationEventUid != KMMFEventCategoryAudioResourceAvailable)
  1.1433 +		{
  1.1434 +		return KErrNotSupported;
  1.1435 +		}
  1.1436 +		
  1.1437 +	iAudioResourceNotificationCallBack = &aCallback;
  1.1438 +	TInt err = iNotificationRegistrationCommands.RegisterAsClient(aNotificationEventUid, aNotificationRegistrationData);
  1.1439 +	if(err == KErrNotReady)
  1.1440 +		{
  1.1441 +		//save the request - so that registration can be attempted on play
  1.1442 +		iArnEventHolder = 	aNotificationEventUid;
  1.1443 +		iNotificationDataHolder = aNotificationRegistrationData;
  1.1444 +		return KErrNone;
  1.1445 +		}
  1.1446 +	iArnEventHolder = KNullUid;
  1.1447 +	iNotificationDataHolder = KNullDesC8;
  1.1448 +	return err;
  1.1449 +	}
  1.1450 +
  1.1451 +//Cancels the registration for audio resource notification.
  1.1452 +TInt CVideoPlayerUtility::CBody::CancelRegisterAudioResourceNotification(TUid aNotificationEventId)
  1.1453 +	{
  1.1454 +	//if not valid notification event id, return;
  1.1455 +	if(aNotificationEventId != KMMFEventCategoryAudioResourceAvailable)
  1.1456 +		{
  1.1457 +		return KErrNotSupported;
  1.1458 +		}
  1.1459 +	TInt err = iNotificationRegistrationCommands.CancelRegisterAsClient(aNotificationEventId);
  1.1460 +	if(err == KErrNotReady)
  1.1461 +		{
  1.1462 +		if(iArnEventHolder == KNullUid)	
  1.1463 +			{
  1.1464 +			return KErrCancel;
  1.1465 +			}
  1.1466 +		//iArnEventHolder has data to re-attempt registration ;
  1.1467 +		//but reattempt is not made(which is done in play);hence return KErrNone
  1.1468 +		iArnEventHolder = KNullUid;
  1.1469 +		iNotificationDataHolder = KNullDesC8;
  1.1470 +		return KErrNone;
  1.1471 +		}
  1.1472 +	return err;
  1.1473 +	}
  1.1474 +
  1.1475 +//Waits for the client to resume the play even after the default timer expires.
  1.1476 +TInt CVideoPlayerUtility::CBody::WillResumePlay()
  1.1477 +	{
  1.1478 +	return iNotificationRegistrationCommands.WillResumePlay();
  1.1479 +	}
  1.1480 +
  1.1481 +// This method will fail with KErrNotSupported when using CVideoPlayerUtility2, otherwise
  1.1482 +// set the screen number.
  1.1483 +TInt CVideoPlayerUtility::CBody::SetInitScreenNumber(TInt aScreenNumber)
  1.1484 +	{
  1.1485 +#ifdef SYMBIAN_BUILD_GCE
  1.1486 +	// If the method is called from CVideoPlayerUtility2, return KErrNotSupport
  1.1487 +	if (iUsingVPU2)
  1.1488 +		{
  1.1489 +		return KErrNotSupported;
  1.1490 +		}
  1.1491 +#endif
  1.1492 +		
  1.1493 +#ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
  1.1494 +	iScreenNumber = aScreenNumber;
  1.1495 +	return KErrNone;
  1.1496 +#else
  1.1497 +	aScreenNumber = aScreenNumber;//added to remove the warning
  1.1498 +	return KErrNotSupported;
  1.1499 +#endif
  1.1500 +	}
  1.1501 +
  1.1502 +#ifdef SYMBIAN_BUILD_GCE
  1.1503 +//-------------------------------------------------------------------------------
  1.1504 +
  1.1505 +void CVideoPlayerUtility::CBody::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, 
  1.1506 +							RWindow& aWindow, const TRect& aVideoExtent, 
  1.1507 +							const TRect& aWindowClipRect)
  1.1508 +	{
  1.1509 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL++");
  1.1510 +    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::AddDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
  1.1511 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
  1.1512 +    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);
  1.1513 +    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
  1.1514 +    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
  1.1515 +
  1.1516 +    // set window and get display ID for the window
  1.1517 +	TRect windowRect = TRect(aWindow.Size()); 
  1.1518 +	
  1.1519 +	// Check the rectangle is contained completely within the window
  1.1520 +	if (!RectContains(windowRect, aWindowClipRect))
  1.1521 +		{
  1.1522 +		// NOTE: TRect::Contains() is not used for comparison here as point located on the right hand 
  1.1523 +		//       side or bottom is considered to be outside the rectangle, which is not the desirable 
  1.1524 +		//       behaviour in this case
  1.1525 +		User::Leave(KErrArgument);
  1.1526 +		}
  1.1527 +		
  1.1528 +	DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, aWindowClipRect, aVideoExtent, &aWindow);
  1.1529 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL--");
  1.1530 +	}
  1.1531 +	
  1.1532 +void CVideoPlayerUtility::CBody::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
  1.1533 +	{
  1.1534 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL++");
  1.1535 +    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::AddDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
  1.1536 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
  1.1537 +    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);
  1.1538 +
  1.1539 +    DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, TRect(aWindow.Size()), TRect(aWindow.Size()), &aWindow);
  1.1540 +
  1.1541 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL--");
  1.1542 +	}
  1.1543 +
  1.1544 +void CVideoPlayerUtility::CBody::DoAddDisplayWindowL(RWsSession& aWs, TInt aDisplayId, RWindowBase& aWindow,
  1.1545 +								const TRect& aClipRect, const TRect& aVideoExtent, RWindow* aWindow2)
  1.1546 +	{
  1.1547 +	iWs = &aWs;
  1.1548 +
  1.1549 +	// check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
  1.1550 +	if (!iControllerOpen)
  1.1551 +		{
  1.1552 +		User::Leave(KErrNotReady);
  1.1553 +		}
  1.1554 +
  1.1555 +	// make sure window isn't already added on another display
  1.1556 +	TRAPD(err, CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
  1.1557 +	if (err != KErrNotFound)
  1.1558 +		{
  1.1559 +		// If err is something else but KErrNone leave
  1.1560 +		User::LeaveIfError(err);
  1.1561 +		// Window is already in use
  1.1562 +		User::Leave(KErrInUse);
  1.1563 +		}
  1.1564 +
  1.1565 +	TInt pos = iActiveDisplays.FindInOrder(aDisplayId, CMediaClientVideoDisplayBody::CompareByDisplay);
  1.1566 +	CMediaClientVideoDisplayBody* display = NULL;
  1.1567 +
  1.1568 +	if (pos == KErrNotFound)
  1.1569 +		{
  1.1570 +		if(iSurfaceId.IsNull())
  1.1571 +			{
  1.1572 +			display = CMediaClientVideoDisplayBody::NewL(aDisplayId, ETrue);
  1.1573 +			}
  1.1574 +		else
  1.1575 +			{
  1.1576 +			display = CMediaClientVideoDisplayBody::NewL(aDisplayId, iSurfaceId, iSurfaceCropRect, iAspectRatio, ETrue);
  1.1577 +			}
  1.1578 +		CleanupStack::PushL(display);
  1.1579 +		iActiveDisplays.InsertInOrderL(display, CMediaClientVideoDisplayBody::Compare);
  1.1580 +		CleanupStack::Pop(display);
  1.1581 +		}
  1.1582 +	else 
  1.1583 +		{
  1.1584 +		User::LeaveIfError(pos);
  1.1585 +		display = iActiveDisplays[pos];
  1.1586 +		}
  1.1587 +
  1.1588 +	display->AddDisplayWindowL(&aWindow, aClipRect, iCropRegion, aVideoExtent, iGlobalScaleWidth, iGlobalScaleHeight,
  1.1589 +								iGlobalRotation, iGlobalAutoScaleType, iGlobalHorizPos, iGlobalVertPos, aWindow2);
  1.1590 +
  1.1591 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1592 +	if (iSubtitleUtility)
  1.1593 +		{
  1.1594 +		// subtitles were enabled already, so enable subtitles on this window
  1.1595 +		TMMFSubtitleWindowConfig config;
  1.1596 +		config.iWindowId = aWindow.WsHandle();
  1.1597 +		config.iWindowClipRect = aClipRect;
  1.1598 +		config.iDisplayMode = aWindow.DisplayMode();
  1.1599 +		config.iRotation = iGlobalRotation;
  1.1600 +		iSubtitleUtility->AddSubtitleConfig(config); // ignore error from add subtitle config because the window can still display video properly
  1.1601 +		}
  1.1602 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1603 +	}
  1.1604 +
  1.1605 +void CVideoPlayerUtility::CBody::DoUpdateDisplayWindowL(RWsSession& aWs, RWindowBase& aWindow,
  1.1606 +                                const TRect& aClipRect, const TRect& aVideoExtent, RWindow* aWindow2)
  1.1607 +    {
  1.1608 +    iWs = &aWs;
  1.1609 +
  1.1610 +    // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
  1.1611 +    if (!iControllerOpen)
  1.1612 +        {
  1.1613 +        User::Leave(KErrNotReady);
  1.1614 +        }
  1.1615 +
  1.1616 +    CMediaClientVideoDisplayBody* display = NULL;
  1.1617 +    TRAPD(err, display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
  1.1618 +    User::LeaveIfError(err);
  1.1619 +
  1.1620 +    display->UpdateDisplayWindowL(&aWindow, aClipRect, iCropRegion, aVideoExtent, iGlobalScaleWidth, iGlobalScaleHeight,
  1.1621 +                                iGlobalRotation, iGlobalAutoScaleType, iGlobalHorizPos, iGlobalVertPos, aWindow2);
  1.1622 +
  1.1623 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1624 +    if (iSubtitleUtility)
  1.1625 +        {
  1.1626 +        // subtitles were enabled already, so update subtitles on this window
  1.1627 +        TMMFSubtitleWindowConfig config;
  1.1628 +        config.iWindowId = aWindow.WsHandle();
  1.1629 +        config.iWindowClipRect = aClipRect;
  1.1630 +        config.iDisplayMode = aWindow.DisplayMode();
  1.1631 +        config.iRotation = iGlobalRotation;
  1.1632 +        iSubtitleUtility->UpdateSubtitleConfig(config); // ignore error from add subtitle config because the window can still display video properly
  1.1633 +        }
  1.1634 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1635 +    }
  1.1636 +
  1.1637 +void CVideoPlayerUtility::CBody::RemoveDisplayWindow(RWindowBase& aWindow)
  1.1638 +	{
  1.1639 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplayWindow++");
  1.1640 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveDisplayWindow - aWindow WsHandle 0x%X", aWindow.WsHandle());
  1.1641 +
  1.1642 +    CMediaClientVideoDisplayBody* display = NULL;
  1.1643 +	TRAPD(err, display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
  1.1644 +	
  1.1645 +	if (err == KErrNone)
  1.1646 +		{		
  1.1647 +		display->RemoveDisplayWindow(aWindow);
  1.1648 +	
  1.1649 +		if (!display->IsUsed())
  1.1650 +
  1.1651 +			{
  1.1652 +			TInt pos = iActiveDisplays.Find(display);
  1.1653 +			iActiveDisplays.Remove(pos);
  1.1654 +			delete display;
  1.1655 +			}
  1.1656 +
  1.1657 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1658 +		if (iSubtitleUtility)
  1.1659 +			{
  1.1660 +			// subtitles are enabled, so remove window config, ignore error
  1.1661 +			iSubtitleUtility->RemoveSubtitleConfig(aWindow.WsHandle());
  1.1662 +			}
  1.1663 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1664 +		}	
  1.1665 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplayWindow--");
  1.1666 +	}
  1.1667 +
  1.1668 +void CVideoPlayerUtility::CBody::AddDisplayL(TInt aDisplay, MMMFSurfaceEventHandler& aEventHandler)
  1.1669 +	{
  1.1670 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayL");
  1.1671 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayL - aDisplay %d", aDisplay);
  1.1672 +	if (!iControllerOpen)
  1.1673 +		{
  1.1674 +		User::Leave(KErrNotReady);
  1.1675 +		}
  1.1676 +	
  1.1677 +	TInt err = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
  1.1678 +	
  1.1679 +	if (err == KErrNotFound)
  1.1680 +		{
  1.1681 +		CMediaClientVideoDisplayBody* display;
  1.1682 +		if(iSurfaceId.IsNull())
  1.1683 +			{
  1.1684 +			display = CMediaClientVideoDisplayBody::NewL(aDisplay, ETrue);
  1.1685 +			}
  1.1686 +		else
  1.1687 +			{
  1.1688 +			display = CMediaClientVideoDisplayBody::NewL(aDisplay, iSurfaceId, iSurfaceCropRect, iAspectRatio, ETrue);
  1.1689 +			}
  1.1690 +		CleanupStack::PushL(display);
  1.1691 +		iActiveDisplays.InsertInOrderL(display, CMediaClientVideoDisplayBody::Compare);
  1.1692 +		CleanupStack::Pop(display);
  1.1693 +		display->AddDisplayL(aEventHandler);
  1.1694 +		}
  1.1695 +	else
  1.1696 +		{
  1.1697 +		User::LeaveIfError(err);
  1.1698 +		iActiveDisplays[err]->AddDisplayL(aEventHandler);
  1.1699 +		}
  1.1700 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayL--");
  1.1701 +	}
  1.1702 +
  1.1703 +void CVideoPlayerUtility::CBody::RemoveDisplay(TInt aDisplay)
  1.1704 +	{
  1.1705 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplay++");
  1.1706 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveDisplay - aDisplay %d", aDisplay);
  1.1707 +	TInt pos = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
  1.1708 +	
  1.1709 +	if (pos >= KErrNone)
  1.1710 +		{
  1.1711 +		CMediaClientVideoDisplayBody* disp = iActiveDisplays[pos];
  1.1712 +		disp->RemoveDisplay();
  1.1713 +		
  1.1714 +		if (!disp->HasWindows())
  1.1715 +			{
  1.1716 +			iActiveDisplays.Remove(pos);
  1.1717 +			delete disp;
  1.1718 +			}
  1.1719 +		}
  1.1720 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplay--");
  1.1721 +	}
  1.1722 +
  1.1723 +void CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow(
  1.1724 +            const RWindowBase& aWindow,
  1.1725 +            const TRect& aFromWindowRect,
  1.1726 +            const TRect& aFromClipRect,
  1.1727 +            TRect& aToWindowRect,
  1.1728 +            TRect& aToClipRect)
  1.1729 +    {
  1.1730 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow++");
  1.1731 +    TPoint windowOrigin = aWindow.AbsPosition();
  1.1732 +    
  1.1733 +    // window rect
  1.1734 +    aToWindowRect.iTl.iX = aFromWindowRect.iTl.iX - windowOrigin.iX;
  1.1735 +    aToWindowRect.iTl.iY = aFromWindowRect.iTl.iY - windowOrigin.iY;
  1.1736 +    aToWindowRect.iBr.iX = aFromWindowRect.iBr.iX - windowOrigin.iX;
  1.1737 +    aToWindowRect.iBr.iY = aFromWindowRect.iBr.iY - windowOrigin.iY;
  1.1738 +    
  1.1739 +    // clip rect
  1.1740 +    aToClipRect.iTl.iX = aFromClipRect.iTl.iX - windowOrigin.iX;
  1.1741 +    aToClipRect.iTl.iY = aFromClipRect.iTl.iY - windowOrigin.iY;
  1.1742 +    aToClipRect.iBr.iX = aFromClipRect.iBr.iX - windowOrigin.iX;
  1.1743 +    aToClipRect.iBr.iY = aFromClipRect.iBr.iY - windowOrigin.iY;
  1.1744 +
  1.1745 +    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow - New Window rect %d,%d - %d,%d", aToWindowRect.iTl.iX, aToWindowRect.iTl.iY, aToWindowRect.iBr.iX, aToWindowRect.iBr.iY);
  1.1746 +    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow - New Clip rect %d,%d - %d,%d", aToClipRect.iTl.iX, aToClipRect.iTl.iY, aToClipRect.iBr.iX, aToClipRect.iBr.iY);
  1.1747 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow--");
  1.1748 +    }
  1.1749 +
  1.1750 +void CVideoPlayerUtility::CBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent)
  1.1751 +	{
  1.1752 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetVideoExtentL++");
  1.1753 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetVideoExtentL - aWindow WsHandle 0x%X", aWindow.WsHandle());
  1.1754 +    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetVideoExtentL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
  1.1755 +
  1.1756 +    // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
  1.1757 +	if (!iControllerOpen)
  1.1758 +		{
  1.1759 +		User::Leave(KErrNotReady);
  1.1760 +		}
  1.1761 +		
  1.1762 +	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
  1.1763 +	display->SetVideoExtentL(aWindow, aVideoExtent, iCropRegion);
  1.1764 +
  1.1765 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetVideoExtentL--");
  1.1766 +	}
  1.1767 +
  1.1768 +void CVideoPlayerUtility::CBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect)
  1.1769 +	{
  1.1770 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetWindowClipRectL++");
  1.1771 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetWindowClipRectL - aWindow WsHandle 0x%X", aWindow.WsHandle());
  1.1772 +    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetWindowClipRectL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
  1.1773 +
  1.1774 +    // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
  1.1775 +	if (!iControllerOpen)
  1.1776 +		{
  1.1777 +		User::Leave(KErrNotReady);
  1.1778 +		}
  1.1779 +
  1.1780 +	TRect winRect(aWindow.Size());
  1.1781 +
  1.1782 +	if (!RectContains(winRect, aWindowClipRect))
  1.1783 +		{
  1.1784 +		User::Leave(KErrArgument);
  1.1785 +		}
  1.1786 +		
  1.1787 +	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
  1.1788 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1789 +	RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
  1.1790 +	TInt pos = windows.Find(aWindow.WsHandle(), CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
  1.1791 +	User::LeaveIfError(pos);
  1.1792 +	
  1.1793 +	CMediaClientVideoDisplayBody::TWindowData& currentWin = windows[pos];
  1.1794 +	if (currentWin.iClipRect != aWindowClipRect)
  1.1795 +		{
  1.1796 +		// update config only if setting has actually changed
  1.1797 +		display->SetWindowClipRectL(aWindow, aWindowClipRect, iCropRegion);
  1.1798 +
  1.1799 +		if (iSubtitleUtility)
  1.1800 +			{
  1.1801 +			TMMFSubtitleWindowConfig config;
  1.1802 +			GetSubtitleConfigFromWindowData(currentWin, config);
  1.1803 +
  1.1804 +			iSubtitleUtility->UpdateSubtitleConfig(config);
  1.1805 +			}
  1.1806 +		}
  1.1807 +#else
  1.1808 +	display->SetWindowClipRectL(aWindow, aWindowClipRect, iCropRegion);
  1.1809 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1810 +
  1.1811 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetWindowClipRectL--");
  1.1812 +	}
  1.1813 +
  1.1814 +// Check if the controller supports the graphics surface. Has to be called after resource opened.
  1.1815 +TInt CVideoPlayerUtility::CBody::CheckSurfaceSupported()
  1.1816 +	{
  1.1817 +	TInt err = iFindAndOpenController->SurfaceSupported();
  1.1818 +		
  1.1819 +	if (err == KErrNone)
  1.1820 +		{
  1.1821 +		iGraphicsSurfaceSupported = ETrue;
  1.1822 +		}
  1.1823 +	else 
  1.1824 +		{
  1.1825 +		iGraphicsSurfaceSupported = EFalse;
  1.1826 +		}
  1.1827 +		
  1.1828 +	return err;
  1.1829 +	}
  1.1830 +
  1.1831 +TBool CVideoPlayerUtility::CBody::RectContains(const TRect& aLeft, const TRect& aRight)
  1.1832 +	{
  1.1833 +	return !(aLeft.iTl.iX > aRight.iTl.iX || 
  1.1834 +			aLeft.iTl.iY > aRight.iTl.iY ||
  1.1835 +	    	aLeft.iBr.iX < aRight.iBr.iX || 
  1.1836 +	    	aLeft.iBr.iY < aRight.iBr.iY);
  1.1837 +	}
  1.1838 +	
  1.1839 +	
  1.1840 +void CVideoPlayerUtility::CBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType)
  1.1841 +	{
  1.1842 +	SetAutoScaleL(aWindow, aScaleType, EHorizontalAlignCenter, EVerticalAlignCenter);
  1.1843 +	}
  1.1844 +	
  1.1845 +void CVideoPlayerUtility::CBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
  1.1846 +	{
  1.1847 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL++");
  1.1848 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
  1.1849 +    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetAutoScaleL - aScaleType %d, aHorizPos %d, aVertPos %d", aScaleType, aHorizPos, aVertPos);
  1.1850 +
  1.1851 +    if (!iControllerOpen)
  1.1852 +		{
  1.1853 +		User::Leave(KErrNotReady);
  1.1854 +		}
  1.1855 +		
  1.1856 +	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
  1.1857 +	display->SetAutoScaleL(aWindow, aScaleType, aHorizPos, aVertPos, iCropRegion);
  1.1858 +
  1.1859 +	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL--");
  1.1860 +	}
  1.1861 +
  1.1862 +void CVideoPlayerUtility::CBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation)
  1.1863 +	{
  1.1864 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL++");
  1.1865 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
  1.1866 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aRotation %d", aRotation);
  1.1867 +
  1.1868 +    if (!iControllerOpen)
  1.1869 +		{
  1.1870 +		User::Leave(KErrNotReady);
  1.1871 +		}
  1.1872 +
  1.1873 +	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
  1.1874 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1875 +	RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
  1.1876 +	TInt pos = windows.Find(aWindow.WsHandle(), CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
  1.1877 +	User::LeaveIfError(pos);
  1.1878 +	
  1.1879 +	CMediaClientVideoDisplayBody::TWindowData& currentWin = windows[pos];
  1.1880 +	if (currentWin.iRotation != aRotation)
  1.1881 +		{
  1.1882 +		display->SetRotationL(aWindow, aRotation, iCropRegion);
  1.1883 +
  1.1884 +		if (iSubtitleUtility)
  1.1885 +			{
  1.1886 +			TMMFSubtitleWindowConfig config;
  1.1887 +			GetSubtitleConfigFromWindowData(currentWin, config);
  1.1888 +
  1.1889 +			iSubtitleUtility->UpdateSubtitleConfig(config);
  1.1890 +			}
  1.1891 +		}
  1.1892 +#else
  1.1893 +	display->SetRotationL(aWindow, aRotation, iCropRegion);
  1.1894 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.1895 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL--");
  1.1896 +	}
  1.1897 +	
  1.1898 +TVideoRotation CVideoPlayerUtility::CBody::RotationL(const RWindowBase& aWindow) const
  1.1899 +	{
  1.1900 +	if (!iControllerOpen)
  1.1901 +		{
  1.1902 +		User::Leave(KErrNotReady);
  1.1903 +		}
  1.1904 +	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
  1.1905 +	return display->RotationL(aWindow);
  1.1906 +	}
  1.1907 +	
  1.1908 +void CVideoPlayerUtility::CBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage)
  1.1909 +	{
  1.1910 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL++");
  1.1911 +    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetScaleFactorL - aWindow WsHandle 0x%X", aWindow.WsHandle());
  1.1912 +    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
  1.1913 +	if (!iControllerOpen)
  1.1914 +		{
  1.1915 +		User::Leave(KErrNotReady);
  1.1916 +		
  1.1917 +		}
  1.1918 +	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
  1.1919 +	display->SetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage, iCropRegion);
  1.1920 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL--");
  1.1921 +	}
  1.1922 +	
  1.1923 +void CVideoPlayerUtility::CBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage) const
  1.1924 +	{
  1.1925 +	if (!iControllerOpen)
  1.1926 +		{
  1.1927 +		User::Leave(KErrNotReady);
  1.1928 +		
  1.1929 +		}
  1.1930 +	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
  1.1931 +	display->GetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage);
  1.1932 +	}
  1.1933 +
  1.1934 +void CVideoPlayerUtility::CBody::SetExternalDisplaySwitchingL(TInt aDisplay, TBool aControl)
  1.1935 +    {
  1.1936 +    TInt pos = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
  1.1937 +    
  1.1938 +    User::LeaveIfError(pos);
  1.1939 +    
  1.1940 +    iActiveDisplays[pos]->SetExternalDisplaySwitchingL(aControl);
  1.1941 +    }
  1.1942 +
  1.1943 +#endif // SYMBIAN_BUILD_GCE
  1.1944 +
  1.1945 +void CVideoPlayerUtility::CBody::SetPlayVelocityL(TInt aVelocity)
  1.1946 +	{
  1.1947 +	// Leave if Open is not yet called on controller.
  1.1948 +	if(!iEventOpenReceived)
  1.1949 +		{
  1.1950 +		User::Leave(KErrNotReady);
  1.1951 +		}
  1.1952 +	
  1.1953 +	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetPlayVelocity(aVelocity));	
  1.1954 +	}
  1.1955 +
  1.1956 +const TInt KDefaultPlayVelocity = 100;
  1.1957 +
  1.1958 +TInt CVideoPlayerUtility::CBody::PlayVelocityL() const
  1.1959 +	{
  1.1960 +	TInt velocity;
  1.1961 +	TInt error;
  1.1962 +
  1.1963 +	// Leave if Open is not yet called.
  1.1964 +	if( !iEventOpenReceived )
  1.1965 +		{
  1.1966 +		User::Leave(KErrNotReady);
  1.1967 +		}
  1.1968 +	
  1.1969 +	error = iVideoPlayControllerExtCustomCommands.PlayVelocity(velocity);
  1.1970 +	/* if customcommand is not implemented by controller pluggin return default value(100) */
  1.1971 +	if (KErrNotSupported == error)
  1.1972 +		{
  1.1973 +		velocity = KDefaultPlayVelocity;
  1.1974 +		}
  1.1975 +	else
  1.1976 +		{
  1.1977 +		User::LeaveIfError(	error );	
  1.1978 +		}
  1.1979 +	return velocity;
  1.1980 +	}
  1.1981 +void CVideoPlayerUtility::CBody::StepFrameL(TInt aStep)
  1.1982 +	{
  1.1983 +	//Leave if not in paused state. This functionality is supported only in paused state.
  1.1984 +	if( (!iEventOpenReceived ) || ( EPaused != iState ) )
  1.1985 +		{
  1.1986 +		User::Leave(KErrNotReady);
  1.1987 +		}
  1.1988 +
  1.1989 +	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.StepFrame(aStep));
  1.1990 +	}
  1.1991 +void CVideoPlayerUtility::CBody::GetPlayRateCapabilitiesL(TVideoPlayRateCapabilities& aCapabilities) const
  1.1992 +	{
  1.1993 +	TInt error;
  1.1994 +
  1.1995 +	// Leave if Open is not yet called on controller.
  1.1996 +	if( !iEventOpenReceived )
  1.1997 +		{
  1.1998 +		User::Leave(KErrNotReady);
  1.1999 +		}
  1.2000 +	
  1.2001 +	error = iVideoPlayControllerExtCustomCommands.GetPlayRateCapabilities(aCapabilities);
  1.2002 +	/* if customcommand is not implemented by controller pluggin return not supported */
  1.2003 +	if (KErrNotSupported == error)
  1.2004 +		{
  1.2005 +		aCapabilities.iPlayBackward = EFalse;
  1.2006 +		aCapabilities.iPlayForward = EFalse;
  1.2007 +		aCapabilities.iStepBackward = EFalse;
  1.2008 +		aCapabilities.iStepForward = EFalse;
  1.2009 +		}
  1.2010 +	else
  1.2011 +		{
  1.2012 +		User::LeaveIfError(error);
  1.2013 +		}	
  1.2014 +	}
  1.2015 +void CVideoPlayerUtility::CBody::SetVideoEnabledL(TBool aVideoEnabled)
  1.2016 +	{
  1.2017 +	// Leave if Open is not yet called or not in stopped state.
  1.2018 +	if( (!iEventOpenReceived ) || ( EStopped != iState ) )
  1.2019 +		{
  1.2020 +		User::Leave(KErrNotReady);
  1.2021 +		}
  1.2022 +	
  1.2023 +	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetVideoEnabled(aVideoEnabled));
  1.2024 +	}
  1.2025 +TBool CVideoPlayerUtility::CBody::VideoEnabledL() const
  1.2026 +	{
  1.2027 +	TBool videoEnabled;
  1.2028 +	TInt error;
  1.2029 +
  1.2030 +	// Leave if Open is not yet called.
  1.2031 +	if( !iEventOpenReceived )
  1.2032 +		{
  1.2033 +		User::Leave(KErrNotReady);
  1.2034 +		}
  1.2035 +	
  1.2036 +	error = iVideoPlayControllerExtCustomCommands.VideoEnabled(videoEnabled);
  1.2037 +	/* if customcommand is not implemented by controller pluggin return default value ETrue */
  1.2038 +	if (KErrNotSupported == error)
  1.2039 +		{
  1.2040 +		videoEnabled = ETrue;
  1.2041 +		}
  1.2042 +	else
  1.2043 +		{
  1.2044 +		User::LeaveIfError(error);
  1.2045 +		}	
  1.2046 +	return videoEnabled;
  1.2047 +	}
  1.2048 +void CVideoPlayerUtility::CBody::SetAudioEnabledL(TBool aAudioEnabled)
  1.2049 +	{
  1.2050 +	// Leave if Open is not yet called or not in stopped state.
  1.2051 +	if( (!iEventOpenReceived ) || ( EStopped != iState ) )
  1.2052 +		{
  1.2053 +		User::Leave(KErrNotReady);
  1.2054 +		}
  1.2055 +	
  1.2056 +	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAudioEnabled(aAudioEnabled));
  1.2057 +	}
  1.2058 +void CVideoPlayerUtility::CBody::SetAutoScaleL(TAutoScaleType aScaleType)
  1.2059 +	{
  1.2060 +	SetAutoScaleL(aScaleType, EHorizontalAlignCenter, EVerticalAlignCenter);
  1.2061 +	}
  1.2062 +void CVideoPlayerUtility::CBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
  1.2063 +	{
  1.2064 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL++");
  1.2065 +    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetAutoScaleL - aScaleType %d, aHorizPos %d, aVertPos %d", aScaleType, aHorizPos, aVertPos);
  1.2066 +
  1.2067 +    // Leave if Open is not yet called.
  1.2068 +	if(!iEventOpenReceived )
  1.2069 +		{
  1.2070 +		User::Leave(KErrNotReady);
  1.2071 +		}	
  1.2072 +
  1.2073 +#ifdef SYMBIAN_BUILD_GCE
  1.2074 +	if (!iGraphicsSurfaceSupported)
  1.2075 +		{
  1.2076 +		User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAutoScale(aScaleType, aHorizPos, aVertPos));
  1.2077 +		}
  1.2078 +	else
  1.2079 +		{
  1.2080 +		// Auto scale setting is not sent to controller when graphics surfaces are used.
  1.2081 +		// If the surface has been created, perform auto scale with the help of graphics surfaces;
  1.2082 +		// otherwise, just store the auto scale info.
  1.2083 +		iGlobalAutoScaleType = aScaleType;
  1.2084 +		iGlobalHorizPos = aHorizPos;
  1.2085 +		iGlobalVertPos = aVertPos;
  1.2086 +		
  1.2087 +		TInt count = iActiveDisplays.Count();
  1.2088 +		
  1.2089 +		for (TInt i = 0; i < count; ++i)
  1.2090 +			{
  1.2091 +			iActiveDisplays[i]->SetAutoScaleL(aScaleType, aHorizPos, aVertPos, iCropRegion);
  1.2092 +			}
  1.2093 +		}
  1.2094 +#else
  1.2095 +	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAutoScale(aScaleType, aHorizPos, aVertPos));
  1.2096 +#endif // SYMBIAN_BUILD_GCE
  1.2097 +    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL--");
  1.2098 +	}
  1.2099 +
  1.2100 +#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.2101 +TBool CVideoPlayerUtility::CBody::SubtitlesAvailable()
  1.2102 +	{
  1.2103 +	if (!iControllerOpen)
  1.2104 +		{
  1.2105 +		return EFalse;
  1.2106 +		}
  1.2107 +
  1.2108 +	return CMMFSubtitleUtility::SubtitlesAvailable(iController);
  1.2109 +	}
  1.2110 +
  1.2111 +void CVideoPlayerUtility::CBody::EnableSubtitlesL()
  1.2112 +	{
  1.2113 +	// Check if video file and controller is opened
  1.2114 +	__ASSERT_ALWAYS(iControllerOpen, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilityFileNotOpened, KErrNotReady));
  1.2115 +	// Check if subtitles are already enabled
  1.2116 +	__ASSERT_ALWAYS(!iSubtitleUtility, User::Leave(KErrInUse));
  1.2117 +	// Check if display window is added
  1.2118 +	TBool windowsAdded = EFalse;
  1.2119 +	for (TInt i = iActiveDisplays.Count()-1; (i >= 0 && windowsAdded == EFalse); --i)
  1.2120 +		{
  1.2121 +		CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
  1.2122 +		windowsAdded = display->HasWindows();
  1.2123 +		}
  1.2124 +	__ASSERT_ALWAYS(windowsAdded, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilityNoWindowAdded, KErrNotReady));
  1.2125 +
  1.2126 +
  1.2127 +	iSubtitleUtility = CMMFSubtitleUtility::NewL(iController, *iWs);
  1.2128 +	TInt err = iSubtitleUtility->EnableSubtitles();
  1.2129 +	if (KErrNone != err)
  1.2130 +		{
  1.2131 +		delete iSubtitleUtility;
  1.2132 +		iSubtitleUtility = NULL;
  1.2133 +		if (KErrNotSupported == err || KErrNotFound == err)
  1.2134 +			{
  1.2135 +			// controller does not support subtitles or subtitle source not found,
  1.2136 +			// panic client because they should have called SubtitlesAvailable first
  1.2137 +			VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotSupported, err);
  1.2138 +			}
  1.2139 +		
  1.2140 +		// leave in release mode or any other error
  1.2141 +		User::Leave(err);
  1.2142 +		}
  1.2143 +
  1.2144 +	TBool subtitleEnabled = EFalse;
  1.2145 +	TInt count = iActiveDisplays.Count();
  1.2146 +	
  1.2147 +	// add the windows in the orders that they were added
  1.2148 +	for (TInt i = 0; i < count; ++i)
  1.2149 +		{
  1.2150 +		CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
  1.2151 +		err = EnableSubtitles(*display);
  1.2152 +		
  1.2153 +		if (KErrNone == err)
  1.2154 +			{
  1.2155 +			subtitleEnabled = ETrue;
  1.2156 +			}
  1.2157 +		}
  1.2158 +
  1.2159 +	// no subtitle window was enabled successfully, enable subtitle failed
  1.2160 +	if (!subtitleEnabled)
  1.2161 +		{
  1.2162 +		DisableSubtitles();	// disable subtitle on controller side
  1.2163 +		User::Leave(err); // Leave with error returned by last EnableSubtitles call
  1.2164 +		}
  1.2165 +	}
  1.2166 +
  1.2167 +void CVideoPlayerUtility::CBody::DisableSubtitles()
  1.2168 +	{
  1.2169 +	if (iSubtitleUtility)
  1.2170 +		{
  1.2171 +		iSubtitleUtility->DisableSubtitles();
  1.2172 +		
  1.2173 +		delete iSubtitleUtility;
  1.2174 +		iSubtitleUtility = NULL;
  1.2175 +		}
  1.2176 +	}
  1.2177 +
  1.2178 +TArray<TLanguage> CVideoPlayerUtility::CBody::SupportedSubtitleLanguagesL()
  1.2179 +	{
  1.2180 +	// Check if subtitles have been enabled
  1.2181 +	__ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
  1.2182 +
  1.2183 +	return iSubtitleUtility->SupportedSubtitleLanguagesL();
  1.2184 +	}
  1.2185 +
  1.2186 +TLanguage CVideoPlayerUtility::CBody::SubtitleLanguageL()
  1.2187 +	{
  1.2188 +	// Check if subtitles have been enabled
  1.2189 +	__ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
  1.2190 +
  1.2191 +	return iSubtitleUtility->SubtitleLanguage();
  1.2192 +	}
  1.2193 +
  1.2194 +void CVideoPlayerUtility::CBody::SetSubtitleLanguageL(TLanguage aLanguage)
  1.2195 +	{
  1.2196 +	// Check if subtitles have been enabled
  1.2197 +	__ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
  1.2198 +
  1.2199 +	TInt err = iSubtitleUtility->SetSubtitleLanguage(aLanguage);
  1.2200 +	if (KErrNotSupported == err)
  1.2201 +		{
  1.2202 +		// panic on debug because client should call SupportedSubtitleLanguagesL() first
  1.2203 +		VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleLanguageNotSupported, KErrNotSupported);
  1.2204 +		}
  1.2205 +	User::LeaveIfError(err);
  1.2206 +	}
  1.2207 +
  1.2208 +void CVideoPlayerUtility::CBody::RedrawSubtitle(RWindow& aWindow, const TRect &aRect)
  1.2209 +	{
  1.2210 +	if (iSubtitleUtility)
  1.2211 +		{
  1.2212 +		// subtitle is enabled
  1.2213 +		RWindow* window = FindWindowWithWsHandle(iActiveDisplays, aWindow.WsHandle());
  1.2214 +		if (window) // check that window was added for video playback
  1.2215 +			{
  1.2216 +			iSubtitleUtility->RedrawSubtitle(aWindow, aRect);
  1.2217 +			}
  1.2218 +		}
  1.2219 +	// else ignore the redraw request
  1.2220 +	}
  1.2221 +
  1.2222 +RWindow* CVideoPlayerUtility::CBody::FindWindowWithWsHandle(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, TInt aWsHandle)
  1.2223 +	{
  1.2224 +	TInt count = aDisplays.Count();
  1.2225 +	
  1.2226 +	for (TInt i = 0; i < count; ++i)
  1.2227 +		{
  1.2228 +		CMediaClientVideoDisplayBody* display = aDisplays[i];
  1.2229 +		RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
  1.2230 +		TInt pos = windows.Find(aWsHandle, CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
  1.2231 +		if (pos >= 0)
  1.2232 +			{
  1.2233 +			return windows[pos].iWindow2;
  1.2234 +			}
  1.2235 +		}
  1.2236 +		
  1.2237 +	return NULL;
  1.2238 +	}
  1.2239 +
  1.2240 +void CVideoPlayerUtility::CBody::GetSubtitleConfigFromWindowData(CMediaClientVideoDisplayBody::TWindowData& aWindowData, TMMFSubtitleWindowConfig& aConfig)
  1.2241 +	{
  1.2242 +	aConfig.iWindowId = aWindowData.iWindow->WsHandle();
  1.2243 +	aConfig.iWindowClipRect = aWindowData.iClipRect;
  1.2244 +	aConfig.iDisplayMode = aWindowData.iWindow->DisplayMode();
  1.2245 +	aConfig.iRotation = aWindowData.iRotation;
  1.2246 +	
  1.2247 +	}
  1.2248 +TInt CVideoPlayerUtility::CBody::EnableSubtitles(CMediaClientVideoDisplayBody& aDisplay)
  1.2249 +	{
  1.2250 +	TBool windowAdded = EFalse;
  1.2251 +	RArray<CMediaClientVideoDisplayBody::TWindowData> windows = aDisplay.Windows();
  1.2252 +	
  1.2253 + 	TInt count = windows.Count();
  1.2254 +	TInt err = KErrNone;	
  1.2255 +	// add the windows in the orders that they are added
  1.2256 +	for (TInt i = 0; i < count; ++i)
  1.2257 +		{
  1.2258 +		err = AddSubtitleConfig(windows[i]);
  1.2259 +		if (KErrNone == err)
  1.2260 +			{
  1.2261 +			windowAdded = ETrue;
  1.2262 +			}
  1.2263 +		}
  1.2264 +
  1.2265 +	// Return the error code returned by the last AddSubtitleConfig call.
  1.2266 +	if (!windowAdded)
  1.2267 +		{
  1.2268 +		return err;
  1.2269 +		}
  1.2270 +	
  1.2271 +	return KErrNone;
  1.2272 +	}
  1.2273 +
  1.2274 +TInt CVideoPlayerUtility::CBody::AddSubtitleConfig(CMediaClientVideoDisplayBody::TWindowData& aWindowData)
  1.2275 +	{
  1.2276 +	ASSERT(iSubtitleUtility);
  1.2277 +	TMMFSubtitleWindowConfig config;
  1.2278 +	GetSubtitleConfigFromWindowData(aWindowData, config);
  1.2279 +	
  1.2280 +	return iSubtitleUtility->AddSubtitleConfig(config);
  1.2281 +	}
  1.2282 +#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
  1.2283 +