os/mm/mmlibs/mmfw/src/Client/Video/mmfclientvideoplayerbody.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
sl@0
    17
#include <mmf/common/mmfstandardcustomcommands.h>  
sl@0
    18
#include <mmf/common/mmfdrmcustomcommands.h>  
sl@0
    19
#include <mmf/common/mmfvideo.h>
sl@0
    20
#include <mmf/server/mmfdes.h>
sl@0
    21
#include <mmf/server/mmffile.h>
sl@0
    22
#include "mmfvideocallback.h"
sl@0
    23
#include "VideoPlayerBody.h"
sl@0
    24
#include "mmfclientvideocommon.h"
sl@0
    25
#include "mmfclientutility.h"
sl@0
    26
#include "mediaclientvideotrace.h"
sl@0
    27
sl@0
    28
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0
    29
#include <mmf/common/mmfvideoenums.h>
sl@0
    30
#endif
sl@0
    31
sl@0
    32
#ifdef SYMBIAN_BUILD_GCE
sl@0
    33
#include <videoplayer2.h>
sl@0
    34
#include <surfaceeventhandler.h>
sl@0
    35
#endif
sl@0
    36
sl@0
    37
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
    38
#include <mmf/common/mmfpaniccodes.h>
sl@0
    39
#include "mmfsubtitleutility.h"
sl@0
    40
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
    41
sl@0
    42
using namespace ContentAccess;
sl@0
    43
sl@0
    44
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
    45
sl@0
    46
#ifdef _DEBUG
sl@0
    47
void VPUDebugPanicOrLeaveL(TInt aVPUPanicCode, TInt aLeaveCode)
sl@0
    48
	{
sl@0
    49
	_LIT(KMMFVideoPlayerUtilityPanicCategory, "MMFVideoPlayUtil");
sl@0
    50
	User::Panic(KMMFVideoPlayerUtilityPanicCategory, aVPUPanicCode);
sl@0
    51
	User::Leave(aLeaveCode); // added for leavescan
sl@0
    52
	}
sl@0
    53
sl@0
    54
#else
sl@0
    55
void VPUDebugPanicOrLeaveL(TInt /*aVPUPanicCode*/, TInt aLeaveCode)
sl@0
    56
	{
sl@0
    57
	User::Leave(aLeaveCode);
sl@0
    58
	}
sl@0
    59
#endif //_DEBUG
sl@0
    60
sl@0
    61
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
    62
sl@0
    63
CVideoPlayerUtility::CBody* CVideoPlayerUtility::CBody::NewL(CVideoPlayerUtility* aParent,
sl@0
    64
															 MVideoPlayerUtilityObserver& aObserver,
sl@0
    65
															 TInt aPriority,
sl@0
    66
															 TInt aPref,
sl@0
    67
															 RWsSession& aWs,
sl@0
    68
															 CWsScreenDevice& aScreenDevice,
sl@0
    69
															 RWindowBase& aWindow,
sl@0
    70
															 const TRect& aScreenRect,
sl@0
    71
															 const TRect& aClipRect)
sl@0
    72
	{
sl@0
    73
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU1)++");
sl@0
    74
	CBody* self = new(ELeave) CBody(aParent, aObserver, aScreenDevice.GetScreenNumber(), aPriority, aPref);
sl@0
    75
	CleanupStack::PushL(self);
sl@0
    76
	self->ConstructL(aWs, aScreenDevice, aWindow, aScreenRect, aClipRect);
sl@0
    77
	CleanupStack::Pop();
sl@0
    78
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU1)--");
sl@0
    79
	return self;
sl@0
    80
	}
sl@0
    81
sl@0
    82
#ifdef SYMBIAN_BUILD_GCE
sl@0
    83
CVideoPlayerUtility::CBody* CVideoPlayerUtility::CBody::NewL(CVideoPlayerUtility2* aParent,
sl@0
    84
															 MVideoPlayerUtilityObserver& aObserver,
sl@0
    85
															 TInt aPriority,
sl@0
    86
															 TInt aPref)
sl@0
    87
	{
sl@0
    88
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU2)++");
sl@0
    89
	CBody* self = new(ELeave) CBody(aParent, aObserver, aPriority, aPref);
sl@0
    90
	CleanupStack::PushL(self);
sl@0
    91
	self->ConstructL();
sl@0
    92
	CleanupStack::Pop();
sl@0
    93
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU2)--");
sl@0
    94
	return self;
sl@0
    95
	}
sl@0
    96
#endif // SYMBIAN_BUILD_GCE
sl@0
    97
sl@0
    98
CVideoPlayerUtility::CBody::~CBody()
sl@0
    99
	{
sl@0
   100
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::~CBody++");
sl@0
   101
	Close();
sl@0
   102
	
sl@0
   103
	delete iControllerImplementationInformation;
sl@0
   104
	delete iDirectScreenAccess;
sl@0
   105
	delete iFindAndOpenController;
sl@0
   106
	delete iControllerEventMonitor;
sl@0
   107
	delete iFrameCallback;
sl@0
   108
	delete iAsyncCallback;
sl@0
   109
	delete iMimeType;
sl@0
   110
	delete iFrameBitmap;
sl@0
   111
	if (iFbsSessionConnected)
sl@0
   112
		iFbsSession.Disconnect();
sl@0
   113
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::~CBody--");
sl@0
   114
	}
sl@0
   115
sl@0
   116
void CVideoPlayerUtility::CBody::Close()
sl@0
   117
	{
sl@0
   118
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Close++");
sl@0
   119
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
   120
	DisableSubtitles();
sl@0
   121
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
   122
sl@0
   123
	if (iAsyncCallback)
sl@0
   124
		iAsyncCallback->Cancel();
sl@0
   125
	if (iFrameCallback)
sl@0
   126
		iFrameCallback->Cancel();
sl@0
   127
	if (iFindAndOpenController)
sl@0
   128
		iFindAndOpenController->Close();
sl@0
   129
	if (iControllerEventMonitor)
sl@0
   130
		iControllerEventMonitor->Cancel();
sl@0
   131
	if(iControllerImplementationInformation)
sl@0
   132
		{
sl@0
   133
		delete iControllerImplementationInformation;
sl@0
   134
		iControllerImplementationInformation = NULL;
sl@0
   135
		}
sl@0
   136
sl@0
   137
#ifdef SYMBIAN_BUILD_GCE
sl@0
   138
	iActiveDisplays.ResetAndDestroy();
sl@0
   139
	iSurfaceId = TSurfaceId::CreateNullId();
sl@0
   140
#endif
sl@0
   141
sl@0
   142
	iController.Close();	
sl@0
   143
	iControllerUid = KNullUid;
sl@0
   144
	iControllerOpen = EFalse;
sl@0
   145
	iDirectScreenAccessAbort = EFalse;
sl@0
   146
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Close--");
sl@0
   147
	}
sl@0
   148
sl@0
   149
CVideoPlayerUtility::CBody::CBody(CVideoPlayerUtility* aParent,
sl@0
   150
								  MVideoPlayerUtilityObserver& aObserver,
sl@0
   151
								  TInt aScreenNumber,
sl@0
   152
								  TInt aPriority,
sl@0
   153
								  TInt aPref) : 
sl@0
   154
	iVideoControllerCustomCommands(iController),
sl@0
   155
	iVideoPlayControllerCustomCommands(iController),
sl@0
   156
	iAudioPlayDeviceCustomCommands(iController),
sl@0
   157
	iAudioRecordDeviceCustomCommands(iController),
sl@0
   158
	iVideoDRMExtCustomCommands(iController),
sl@0
   159
	iDRMCustomCommands(iController),
sl@0
   160
	iVideoPlayControllerExtCustomCommands(iController),	
sl@0
   161
	iNotificationRegistrationCommands(iController),
sl@0
   162
#ifdef SYMBIAN_BUILD_GCE
sl@0
   163
	iVideoPlaySurfaceSupportCustomCommands(iController),
sl@0
   164
#endif
sl@0
   165
	iArnEventHolder(KNullUid),
sl@0
   166
	iVideoSetInitScreenCustomCommands(iController),
sl@0
   167
	iObserver(aObserver),
sl@0
   168
	iState(EStopped),
sl@0
   169
	iParent(aParent),
sl@0
   170
	iScreenNumber(aScreenNumber)
sl@0
   171
#ifdef SYMBIAN_BUILD_GCE
sl@0
   172
	,iGlobalScaleWidth(100.0f),
sl@0
   173
	iGlobalScaleHeight(100.0f),
sl@0
   174
	iGlobalAutoScaleType(EAutoScaleBestFit),  // Really need some platform specific way of defining this. Not everyone will want it.
sl@0
   175
	iGlobalHorizPos(EHorizontalAlignCenter),
sl@0
   176
	iGlobalVertPos(EVerticalAlignCenter)
sl@0
   177
#endif
sl@0
   178
	{
sl@0
   179
	iPrioritySettings.iPriority = aPriority;
sl@0
   180
	iPrioritySettings.iPref = aPref;
sl@0
   181
	}
sl@0
   182
sl@0
   183
#ifdef SYMBIAN_BUILD_GCE
sl@0
   184
CVideoPlayerUtility::CBody::CBody(CVideoPlayerUtility2* aParent,
sl@0
   185
				MVideoPlayerUtilityObserver& aObserver,
sl@0
   186
				TInt aPriority,
sl@0
   187
				TInt aPref) : 
sl@0
   188
	iVideoControllerCustomCommands(iController),
sl@0
   189
	iVideoPlayControllerCustomCommands(iController),
sl@0
   190
	iAudioPlayDeviceCustomCommands(iController),
sl@0
   191
	iAudioRecordDeviceCustomCommands(iController),
sl@0
   192
	iVideoDRMExtCustomCommands(iController),
sl@0
   193
	iDRMCustomCommands(iController),
sl@0
   194
	iVideoPlayControllerExtCustomCommands(iController),
sl@0
   195
	iNotificationRegistrationCommands(iController),
sl@0
   196
	iVideoPlaySurfaceSupportCustomCommands(iController),
sl@0
   197
	iArnEventHolder(KNullUid),
sl@0
   198
	iVideoSetInitScreenCustomCommands(iController),
sl@0
   199
	iObserver(aObserver),
sl@0
   200
	iState(EStopped),
sl@0
   201
	iParent(aParent),
sl@0
   202
	iUsingVPU2(ETrue),
sl@0
   203
	iGlobalScaleWidth(100.0f),
sl@0
   204
	iGlobalScaleHeight(100.0f),
sl@0
   205
	iGlobalHorizPos(EHorizontalAlignCenter),
sl@0
   206
	iGlobalVertPos(EVerticalAlignCenter)
sl@0
   207
	{
sl@0
   208
	iPrioritySettings.iPriority = aPriority;
sl@0
   209
	iPrioritySettings.iPref = aPref;
sl@0
   210
	}
sl@0
   211
sl@0
   212
void CVideoPlayerUtility::CBody::ConstructL()
sl@0
   213
	{
sl@0
   214
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL1++");
sl@0
   215
	CommonConstructL();
sl@0
   216
	iFindAndOpenController = CMMFFindAndOpenController::NewL(*this);
sl@0
   217
	iFindAndOpenController->SetSurfaceMode(iUsingVPU2, &iVideoPlaySurfaceSupportCustomCommands);
sl@0
   218
	iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
sl@0
   219
	iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EPlayback);
sl@0
   220
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL1--");
sl@0
   221
	}
sl@0
   222
sl@0
   223
#endif // SYMBIAN_BUILD_GCE
sl@0
   224
sl@0
   225
void CVideoPlayerUtility::CBody::ConstructL(RWsSession& aWs,
sl@0
   226
						CWsScreenDevice& aScreenDevice,
sl@0
   227
						RWindowBase& aWindow,
sl@0
   228
						const TRect& aWindowRect,
sl@0
   229
						const TRect& aClipRect)
sl@0
   230
	{
sl@0
   231
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL2++");
sl@0
   232
	CommonConstructL();
sl@0
   233
	
sl@0
   234
	SetDisplayWindowL(aWs, aScreenDevice, aWindow, aWindowRect, aClipRect);
sl@0
   235
	iFindAndOpenController = CMMFFindAndOpenController::NewL(*this);
sl@0
   236
#ifdef SYMBIAN_BUILD_GCE	
sl@0
   237
	iFindAndOpenController->SetSurfaceMode(iUsingVPU2, &iVideoPlaySurfaceSupportCustomCommands);
sl@0
   238
	
sl@0
   239
	// If we open a controller with surface support we may render to surfaces.  We need to store these
sl@0
   240
	// so we can add the display as a surface rendering target.
sl@0
   241
sl@0
   242
	iWs = &aWs;
sl@0
   243
	iDisplayId = aScreenDevice.GetScreenNumber();
sl@0
   244
	iWindow = &aWindow;
sl@0
   245
	iWindowRect = aWindowRect;
sl@0
   246
	iClipRect = aClipRect;	
sl@0
   247
sl@0
   248
#endif
sl@0
   249
	iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
sl@0
   250
	iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EPlayback);
sl@0
   251
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL2--");
sl@0
   252
	}
sl@0
   253
sl@0
   254
void CVideoPlayerUtility::CBody::CommonConstructL()
sl@0
   255
	{
sl@0
   256
	iControllerEventMonitor = CMMFControllerEventMonitor::NewL(*this, iController);
sl@0
   257
	iMimeType = HBufC8::NewL(KMaxMimeTypeLength);
sl@0
   258
	iAsyncCallback = new (ELeave) CMMFVideoPlayerCallback(iObserver);
sl@0
   259
	iFrameCallback = new (ELeave) CMMFVideoPlayerCallback(iObserver);
sl@0
   260
	User::LeaveIfError(iFbsSession.Connect());
sl@0
   261
	iFbsSessionConnected = ETrue;
sl@0
   262
	}
sl@0
   263
sl@0
   264
void CVideoPlayerUtility::CBody::Reset() 
sl@0
   265
	{
sl@0
   266
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Reset++");
sl@0
   267
	Close();
sl@0
   268
	
sl@0
   269
	// reset all state variables
sl@0
   270
	iEventOpenReceived = EFalse;
sl@0
   271
	iCallbackOpenReceived = EFalse;
sl@0
   272
	iOpenError = KErrNone;
sl@0
   273
#ifdef SYMBIAN_BUILD_GCE
sl@0
   274
	iGraphicsSurfaceSupported = EFalse;
sl@0
   275
#endif
sl@0
   276
	iControllerUid = KNullUid;
sl@0
   277
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Reset--");
sl@0
   278
	}
sl@0
   279
sl@0
   280
void CVideoPlayerUtility::CBody::SetAndUpdateWindow()
sl@0
   281
	{
sl@0
   282
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAndUpdateWindow++");
sl@0
   283
	if (iOpenError == KErrNone)	
sl@0
   284
		{
sl@0
   285
		// Set the display window and update display region if the controller doesn't support graphics surface. 		
sl@0
   286
		iOpenError = iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect, iClipRect);
sl@0
   287
		}
sl@0
   288
sl@0
   289
	if (iOpenError == KErrNone && iDirectScreenAccess && iDirectScreenAccess->DrawingRegion())
sl@0
   290
		{
sl@0
   291
		iOpenError = iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion());
sl@0
   292
		}
sl@0
   293
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAndUpdateWindow--");
sl@0
   294
	}
sl@0
   295
sl@0
   296
void CVideoPlayerUtility::CBody::MfaocComplete(		
sl@0
   297
	TInt& aError, 
sl@0
   298
	RMMFController*	/*aController*/,
sl@0
   299
	TUid aControllerUid, 
sl@0
   300
	TMMFMessageDestination* /*aSourceHandle*/, 
sl@0
   301
	TMMFMessageDestination* /*aSinkHandle*/)
sl@0
   302
	{
sl@0
   303
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::MfaocComplete++");
sl@0
   304
    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::MfaocComplete - aError %d, aControllerUid 0x%X", aError, aControllerUid.iUid);
sl@0
   305
	iCallbackOpenReceived = ETrue;
sl@0
   306
sl@0
   307
	// save the error in iOpenError -
sl@0
   308
	// unless HandleEvent(KMMFEventCategoryVideoOpenComplete) 
sl@0
   309
	// has reported an error already
sl@0
   310
	if (iOpenError == KErrNone)
sl@0
   311
		iOpenError = aError;
sl@0
   312
	
sl@0
   313
	if (iOpenError == KErrNone)
sl@0
   314
		{
sl@0
   315
#ifdef SYMBIAN_BUILD_GCE
sl@0
   316
		// Check if the graphics surfaces is supported
sl@0
   317
		TInt err = CheckSurfaceSupported();
sl@0
   318
sl@0
   319
		DEBUG_PRINTF4("CVideoPlayerUtility::CBody::MfaocComplete - Checked surfaces supported - Err %d, Surfaces supported %d, Using VPU2 %d", err, iGraphicsSurfaceSupported, iUsingVPU2);
sl@0
   320
	
sl@0
   321
		if (!iGraphicsSurfaceSupported)
sl@0
   322
			{
sl@0
   323
			if (err != KErrNone && iUsingVPU2)
sl@0
   324
				{
sl@0
   325
				// Set KErrNotSupported if the controller doesn't support graphics surface and 
sl@0
   326
				// the open source is using CVideoPlayerUtility2
sl@0
   327
				iOpenError = err;
sl@0
   328
				}
sl@0
   329
			else
sl@0
   330
				{
sl@0
   331
				SetAndUpdateWindow();
sl@0
   332
				}
sl@0
   333
			}
sl@0
   334
#else
sl@0
   335
		SetAndUpdateWindow();
sl@0
   336
#endif // SYMBIAN_BUILD_GCE	
sl@0
   337
	
sl@0
   338
		// now that the controller is open
sl@0
   339
		if (iOpenError == KErrNone)
sl@0
   340
			{
sl@0
   341
			iControllerOpen = ETrue;
sl@0
   342
			iControllerUid = aControllerUid;
sl@0
   343
sl@0
   344
#ifdef SYMBIAN_BUILD_GCE		
sl@0
   345
			// We are using a controller that supports graphics surfaces but are not in surface mode.  
sl@0
   346
			// Call AddDisplay so we can render to surfaces using the CVideoUtility API.
sl@0
   347
			if (iGraphicsSurfaceSupported && !iUsingVPU2)
sl@0
   348
				{
sl@0
   349
				if (iDirectScreenAccess)
sl@0
   350
					{
sl@0
   351
		 			iDirectScreenAccess->Cancel();
sl@0
   352
					}
sl@0
   353
				
sl@0
   354
		        // When using surfaces for CVPU we use DoAddDisplayWindowL() which requires clip rectangle and video extent
sl@0
   355
		        // as arguments. Video extent is not supported by CVPU so aWindowRect is used instead. This function
sl@0
   356
		        // assumes these args are relative to the window. However they are relative to the display and must be
sl@0
   357
		        // converted.
sl@0
   358
		        TRect windowRectRelativeToWindow;
sl@0
   359
		        TRect clipRectRelativeToWindow;     
sl@0
   360
		        ConvertFromRelativeToDisplayToRelativeToWindow(*iWindow, iWindowRect, iClipRect, windowRectRelativeToWindow, clipRectRelativeToWindow);
sl@0
   361
sl@0
   362
				TRAP(iOpenError, DoAddDisplayWindowL(*iWs, iDisplayId, *iWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL));				
sl@0
   363
				}
sl@0
   364
#endif		
sl@0
   365
			}
sl@0
   366
		// If an error occurred in any of the above, try for next controller if present
sl@0
   367
		// in the selection list.
sl@0
   368
		else
sl@0
   369
			{
sl@0
   370
			if(iFindAndOpenController->ControllerIndex() < (iFindAndOpenController->ControllerCount())-1)
sl@0
   371
				{
sl@0
   372
				aError = iOpenError;
sl@0
   373
				
sl@0
   374
				if (iAsyncCallback)
sl@0
   375
					{
sl@0
   376
					iAsyncCallback->Cancel();
sl@0
   377
					}
sl@0
   378
		
sl@0
   379
				if (iControllerEventMonitor)
sl@0
   380
					{
sl@0
   381
					iControllerEventMonitor->Cancel();
sl@0
   382
					}
sl@0
   383
				iOpenError = KErrNone;
sl@0
   384
					
sl@0
   385
				return;
sl@0
   386
				}
sl@0
   387
				
sl@0
   388
			Close();
sl@0
   389
			}
sl@0
   390
		}
sl@0
   391
sl@0
   392
	if(iOpenError != KErrNone && !iControllerOpen)
sl@0
   393
		{
sl@0
   394
		if (iFindAndOpenController)	
sl@0
   395
			{
sl@0
   396
			//if try next controller was called when specific controller uid was 
sl@0
   397
			//given, skip the searching and report error.
sl@0
   398
			if(!iFindAndOpenController->StopTryLoadController()) 
sl@0
   399
				{
sl@0
   400
				if( !(aError == KErrNoMemory || aError == KErrCancel ) ) 
sl@0
   401
					{
sl@0
   402
					if(iFindAndOpenController->ControllerIndex() < (iFindAndOpenController->ControllerCount())-1)
sl@0
   403
						{
sl@0
   404
						aError = iOpenError;   // Actually tries to load controller
sl@0
   405
						iOpenError = KErrNone;
sl@0
   406
						return;
sl@0
   407
						}
sl@0
   408
					}
sl@0
   409
				}
sl@0
   410
			}
sl@0
   411
		}
sl@0
   412
	
sl@0
   413
	// if we've already received the open complete event
sl@0
   414
	// call the client now (otherwise wait for it)
sl@0
   415
	if (iEventOpenReceived || iOpenError != KErrNone)
sl@0
   416
		{
sl@0
   417
		// stop a subsequent HandleEvent(KMMFEventCategoryVideoOpenComplete) 
sl@0
   418
		// from issuing another callback to client
sl@0
   419
		iCallbackOpenReceived = EFalse;
sl@0
   420
		iAsyncCallback->Signal(iOpenError, CMMFVideoPlayerCallback::EOpenCompleteEvent);
sl@0
   421
		}
sl@0
   422
	
sl@0
   423
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::MfaocComplete--");
sl@0
   424
	}
sl@0
   425
sl@0
   426
void CVideoPlayerUtility::CBody::OpenFileL(const TDesC& aFileName, TUid aControllerUid)
sl@0
   427
	{
sl@0
   428
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filename)++");
sl@0
   429
	TMMFileSource filesource(aFileName, KDefaultContentObject, EPlay);
sl@0
   430
	OpenFileL(filesource, aControllerUid);
sl@0
   431
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filename)--");
sl@0
   432
	}
sl@0
   433
	
sl@0
   434
void CVideoPlayerUtility::CBody::OpenFileL(const RFile& aFile, TUid aControllerUid)
sl@0
   435
	{
sl@0
   436
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filehandle)++");
sl@0
   437
	RFile& file = const_cast<RFile&>(aFile);
sl@0
   438
	TMMFileHandleSource filehandlesource(file, KDefaultContentObject, EPlay);
sl@0
   439
	OpenFileL(filehandlesource, aControllerUid);
sl@0
   440
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filehandle)--");
sl@0
   441
	}
sl@0
   442
sl@0
   443
void CVideoPlayerUtility::CBody::OpenFileL(const TMMSource& aSource, TUid aControllerUid)
sl@0
   444
	{
sl@0
   445
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (source)++");
sl@0
   446
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::OpenFileL - aControllerUid 0x%X", aControllerUid.iUid);
sl@0
   447
	// Make sure we are closed
sl@0
   448
	Reset();
sl@0
   449
sl@0
   450
	iFindAndOpenController->ConfigureSourceSink(
sl@0
   451
		aSource,
sl@0
   452
		CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput));
sl@0
   453
sl@0
   454
#ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
sl@0
   455
	iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
sl@0
   456
#endif
sl@0
   457
sl@0
   458
	if (aControllerUid != KNullUid) 
sl@0
   459
		{
sl@0
   460
		iFindAndOpenController->OpenByControllerUid(aControllerUid);
sl@0
   461
		}
sl@0
   462
	else
sl@0
   463
		{
sl@0
   464
		iFindAndOpenController->OpenByFileSource(aSource);
sl@0
   465
		}
sl@0
   466
sl@0
   467
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (source)--");
sl@0
   468
	}
sl@0
   469
	
sl@0
   470
//
sl@0
   471
// This method launches and initializes plugin controller based on the stream 
sl@0
   472
// source header passed in the descriptor buffer.
sl@0
   473
//
sl@0
   474
void CVideoPlayerUtility::CBody::OpenDesL(const TDesC8& aDescriptor, TUid aControllerUid)
sl@0
   475
	{
sl@0
   476
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenDesL++");
sl@0
   477
	// Make sure we are closed
sl@0
   478
	Reset();
sl@0
   479
sl@0
   480
	iFindAndOpenController->ConfigureSourceSink(
sl@0
   481
		CMMFFindAndOpenController::TSourceSink(KUidMmfDescriptorSource, CMMFFindAndOpenController::GetConfigDescriptor(aDescriptor)), 
sl@0
   482
		CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput, KNullDesC8));
sl@0
   483
	
sl@0
   484
#ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
sl@0
   485
	iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
sl@0
   486
#endif
sl@0
   487
		
sl@0
   488
	if (aControllerUid!=KNullUid)
sl@0
   489
		{
sl@0
   490
		iFindAndOpenController->OpenByControllerUid(aControllerUid);
sl@0
   491
		}
sl@0
   492
	else
sl@0
   493
		{
sl@0
   494
		iFindAndOpenController->OpenByDescriptor(aDescriptor);
sl@0
   495
		}
sl@0
   496
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenDesL--");
sl@0
   497
	}
sl@0
   498
	
sl@0
   499
void CVideoPlayerUtility::CBody::OpenUrlL(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType, TUid aControllerUid)
sl@0
   500
	{
sl@0
   501
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenUrlL++");
sl@0
   502
	// Make sure we are closed
sl@0
   503
	Reset();
sl@0
   504
sl@0
   505
	CBufFlat* urlCfgBuffer = NULL;
sl@0
   506
    CMMFFindAndOpenController::GetConfigUrlL(urlCfgBuffer, aUrl, aIapId);
sl@0
   507
sl@0
   508
	iFindAndOpenController->ConfigureSourceSink(
sl@0
   509
		CMMFFindAndOpenController::TSourceSink(KUidMmfUrlSource, urlCfgBuffer->Ptr(0)), 
sl@0
   510
		CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput, KNullDesC8));
sl@0
   511
	
sl@0
   512
#ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
sl@0
   513
	iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
sl@0
   514
#endif
sl@0
   515
		
sl@0
   516
	if (aControllerUid!=KNullUid)
sl@0
   517
		{
sl@0
   518
		iFindAndOpenController->OpenByControllerUid(aControllerUid);
sl@0
   519
		}
sl@0
   520
	else
sl@0
   521
		iFindAndOpenController->OpenByUrl(aUrl, aIapId, aMimeType);
sl@0
   522
sl@0
   523
	delete urlCfgBuffer;
sl@0
   524
sl@0
   525
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenUrlL--");
sl@0
   526
	}
sl@0
   527
sl@0
   528
void CVideoPlayerUtility::CBody::Play()
sl@0
   529
	{
sl@0
   530
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Play++");
sl@0
   531
	TInt err = iController.Prime();
sl@0
   532
	if (err == KErrNone)
sl@0
   533
		err = iController.Play();
sl@0
   534
	if (err != KErrNone)
sl@0
   535
	    {
sl@0
   536
	    iAsyncCallback->Signal(err,CMMFVideoPlayerCallback::EPlayCompleteEvent);
sl@0
   537
	    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play (exit 1)-- - Err %d", err);
sl@0
   538
	    return;
sl@0
   539
	    }
sl@0
   540
	iState = EPlaying;
sl@0
   541
	//If Audio Resource Notification request is pending - attempt now
sl@0
   542
	if(iArnEventHolder != KNullUid)
sl@0
   543
		{
sl@0
   544
		err = iNotificationRegistrationCommands.RegisterAsClient(iArnEventHolder, iNotificationDataHolder);
sl@0
   545
		iArnEventHolder = KNullUid;
sl@0
   546
		iNotificationDataHolder = KNullDesC8;
sl@0
   547
		if(err != KErrNone)
sl@0
   548
			{
sl@0
   549
			iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
sl@0
   550
			}
sl@0
   551
		}
sl@0
   552
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play-- - Err %d", err);
sl@0
   553
	}
sl@0
   554
sl@0
   555
void CVideoPlayerUtility::CBody::Play(const TTimeIntervalMicroSeconds& aStartTime, const TTimeIntervalMicroSeconds& aEndTime)
sl@0
   556
	{
sl@0
   557
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Play++");
sl@0
   558
    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::Play - aStartTime %ld, aEndTime %ld", aStartTime.Int64(), aEndTime.Int64());
sl@0
   559
	TInt err = iController.Prime();
sl@0
   560
	if (err == KErrNone)
sl@0
   561
	err = iVideoPlayControllerCustomCommands.Play(aStartTime, aEndTime);
sl@0
   562
	if (err != KErrNone)
sl@0
   563
	    {
sl@0
   564
	    iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
sl@0
   565
		DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play (exit1)-- - Err %d", err);
sl@0
   566
	    return;
sl@0
   567
	    }
sl@0
   568
	iState = EPlaying;
sl@0
   569
	//If Audio Resource Notification request is pending - attempt now
sl@0
   570
	if(iArnEventHolder != KNullUid)
sl@0
   571
		{
sl@0
   572
		err = iNotificationRegistrationCommands.RegisterAsClient(iArnEventHolder, iNotificationDataHolder);			
sl@0
   573
		iArnEventHolder = KNullUid;
sl@0
   574
		iNotificationDataHolder = KNullDesC8;
sl@0
   575
		if(err != KErrNone)
sl@0
   576
			{
sl@0
   577
			iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
sl@0
   578
			}
sl@0
   579
		}
sl@0
   580
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play-- - Err %d", err);
sl@0
   581
	}
sl@0
   582
sl@0
   583
sl@0
   584
TInt CVideoPlayerUtility::CBody::Stop()
sl@0
   585
	{
sl@0
   586
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::Stop++");
sl@0
   587
	TInt err = iController.Stop();
sl@0
   588
	iState = EStopped;
sl@0
   589
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Stop-- - Err %d", err);
sl@0
   590
	return err;
sl@0
   591
	}
sl@0
   592
sl@0
   593
void CVideoPlayerUtility::CBody::PauseL()
sl@0
   594
	{
sl@0
   595
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PauseL++");
sl@0
   596
	User::LeaveIfError(iController.Pause());
sl@0
   597
	iState = EPaused;
sl@0
   598
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PauseL--");
sl@0
   599
	}
sl@0
   600
sl@0
   601
void CVideoPlayerUtility::CBody::SetVolumeL(TInt aVolume)
sl@0
   602
	{
sl@0
   603
	User::LeaveIfError(iAudioPlayDeviceCustomCommands.SetVolume(aVolume));
sl@0
   604
	}
sl@0
   605
sl@0
   606
void CVideoPlayerUtility::CBody::PrepareDSAL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow)
sl@0
   607
	{
sl@0
   608
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL++");
sl@0
   609
	CDirectScreenAccess* old = iDirectScreenAccess;
sl@0
   610
	iDirectScreenAccess = CDirectScreenAccess::NewL(aWs,aScreenDevice,aWindow,*this);
sl@0
   611
	delete old;
sl@0
   612
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL - Starting");
sl@0
   613
	iDirectScreenAccess->StartL();
sl@0
   614
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL--");
sl@0
   615
	}
sl@0
   616
sl@0
   617
void CVideoPlayerUtility::CBody::SetDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice,
sl@0
   618
							RWindowBase& aWindow, const TRect& aWindowRect,
sl@0
   619
							const TRect& aClipRect)
sl@0
   620
	{	
sl@0
   621
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetDisplayWindowL++");
sl@0
   622
    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
sl@0
   623
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
   624
    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);
sl@0
   625
    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindowRect %d,%d - %d,%d", aWindowRect.iTl.iX, aWindowRect.iTl.iY, aWindowRect.iBr.iX, aWindowRect.iBr.iY);
sl@0
   626
    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aClipRect %d,%d - %d,%d", aClipRect.iTl.iX, aClipRect.iTl.iY, aClipRect.iBr.iX, aClipRect.iBr.iY);
sl@0
   627
sl@0
   628
    iWindowRect = aWindowRect;
sl@0
   629
	iClipRect = aClipRect;
sl@0
   630
	
sl@0
   631
#ifdef SYMBIAN_BUILD_GCE
sl@0
   632
	// If called from CVideoPlayerUtility2, fail with KErrNotSupport. Otherwise, if the controller supports 
sl@0
   633
	// the graphics surfaces, it will render to graphics surfaces. If the controller doesn't support 
sl@0
   634
	// the graphics surfaces, it will use direct screen access.
sl@0
   635
	if (iUsingVPU2)
sl@0
   636
		{
sl@0
   637
		User::Leave(KErrNotSupported);
sl@0
   638
		}
sl@0
   639
	// If the controller does not support GCE or the source has not been opened, start new DSA.
sl@0
   640
	if (!iGraphicsSurfaceSupported)
sl@0
   641
		{
sl@0
   642
		PrepareDSAL(aWs, aScreenDevice, aWindow);
sl@0
   643
		}
sl@0
   644
sl@0
   645
	if (!iGraphicsSurfaceSupported && iControllerOpen)
sl@0
   646
		{
sl@0
   647
		// Set display window and update region, if controller is open
sl@0
   648
		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect,iClipRect));
sl@0
   649
		User::LeaveIfError(iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion()));
sl@0
   650
		}
sl@0
   651
		
sl@0
   652
	if (iGraphicsSurfaceSupported && iControllerOpen)
sl@0
   653
		{
sl@0
   654
		// When the controller supports graphics surfaces, need to stop direct screen access.
sl@0
   655
 		if (iDirectScreenAccess)
sl@0
   656
 			{
sl@0
   657
 			iDirectScreenAccess->Cancel();
sl@0
   658
  			AbortNow(RDirectScreenAccess::ETerminateCancel);
sl@0
   659
 			}
sl@0
   660
		
sl@0
   661
		// When using surfaces for CVPU we use DoAddDisplayWindowL() which requires clip rectangle and video extent
sl@0
   662
		// as arguments. Video extent is not supported by CVPU so aWindowRect is used instead. This function
sl@0
   663
		// assumes these args are relative to the window. However they are relative to the display and must be
sl@0
   664
		// converted.
sl@0
   665
		TRect windowRectRelativeToWindow;
sl@0
   666
		TRect clipRectRelativeToWindow;		
sl@0
   667
		ConvertFromRelativeToDisplayToRelativeToWindow(aWindow, aWindowRect, aClipRect, windowRectRelativeToWindow, clipRectRelativeToWindow);
sl@0
   668
sl@0
   669
		// check if display for window already exists and if so do an update else create a new display
sl@0
   670
		TRAPD(err, CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
sl@0
   671
		if (err == KErrNone)
sl@0
   672
		    {
sl@0
   673
		    DoUpdateDisplayWindowL(aWs, aWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL);
sl@0
   674
		    }
sl@0
   675
		else
sl@0
   676
		    {
sl@0
   677
		    DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL);
sl@0
   678
		    }
sl@0
   679
		}
sl@0
   680
#else
sl@0
   681
	PrepareDSAL(aWs, aScreenDevice, aWindow);
sl@0
   682
	
sl@0
   683
	if (iControllerOpen)
sl@0
   684
		{
sl@0
   685
		// Set display window and update region, if controller is open
sl@0
   686
		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect,iClipRect));
sl@0
   687
		User::LeaveIfError(iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion()));
sl@0
   688
		if(iDirectScreenAccessAbort)
sl@0
   689
			{
sl@0
   690
			User::LeaveIfError(iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EResumeDSA));
sl@0
   691
			iDirectScreenAccessAbort = EFalse;
sl@0
   692
			}
sl@0
   693
		}
sl@0
   694
#endif
sl@0
   695
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetDisplayWindowL--");
sl@0
   696
	}
sl@0
   697
sl@0
   698
TReal32 CVideoPlayerUtility::CBody::VideoFrameRateL() const
sl@0
   699
	{
sl@0
   700
	TReal32 framerate = 0;
sl@0
   701
	User::LeaveIfError(iVideoControllerCustomCommands.GetFrameRate(framerate));
sl@0
   702
	return framerate;
sl@0
   703
	}
sl@0
   704
sl@0
   705
sl@0
   706
void CVideoPlayerUtility::CBody::VideoFrameSizeL(TSize& aSize) const
sl@0
   707
	{
sl@0
   708
	User::LeaveIfError(iVideoControllerCustomCommands.GetVideoFrameSize(aSize));
sl@0
   709
	}
sl@0
   710
sl@0
   711
TInt CVideoPlayerUtility::CBody::Volume() const
sl@0
   712
	{
sl@0
   713
	TInt vol = 0;
sl@0
   714
	iAudioPlayDeviceCustomCommands.GetVolume(vol);
sl@0
   715
	return vol;
sl@0
   716
	}
sl@0
   717
sl@0
   718
sl@0
   719
void CVideoPlayerUtility::CBody::SetBalanceL(TInt aBalance)
sl@0
   720
	{
sl@0
   721
	User::LeaveIfError(iAudioPlayDeviceCustomCommands.SetBalance(aBalance));
sl@0
   722
	}
sl@0
   723
sl@0
   724
sl@0
   725
TInt CVideoPlayerUtility::CBody::Balance() const
sl@0
   726
	{
sl@0
   727
	TInt bal = 0;
sl@0
   728
	iAudioPlayDeviceCustomCommands.GetBalance(bal);
sl@0
   729
	return bal;
sl@0
   730
	}
sl@0
   731
sl@0
   732
void CVideoPlayerUtility::CBody::SetRotationL(TVideoRotation aRotation)
sl@0
   733
	{
sl@0
   734
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL++");
sl@0
   735
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aRotation %d", aRotation);
sl@0
   736
sl@0
   737
#ifdef SYMBIAN_BUILD_GCE
sl@0
   738
	if (!iGraphicsSurfaceSupported)
sl@0
   739
		{
sl@0
   740
		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetRotation(aRotation));
sl@0
   741
		}
sl@0
   742
	else
sl@0
   743
		{
sl@0
   744
		// Rotation setting is not sent to controller when graphics surfaces are used.
sl@0
   745
		// If the surface has been created, perform rotation with the help of graphics surfaces;
sl@0
   746
		// otherwise, just store the rotation info.
sl@0
   747
sl@0
   748
		TInt count = iActiveDisplays.Count();
sl@0
   749
		
sl@0
   750
		for (TInt i = 0; i < count; ++i)
sl@0
   751
			{
sl@0
   752
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
   753
			CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
sl@0
   754
			RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
sl@0
   755
			TInt windowcount = windows.Count();	
sl@0
   756
			for (TInt i = 0; i < windowcount; ++i)
sl@0
   757
				{
sl@0
   758
				CMediaClientVideoDisplayBody::TWindowData& window = windows[i];		
sl@0
   759
				if (window.iRotation != aRotation)
sl@0
   760
					{
sl@0
   761
					// update config only if setting has actually changed
sl@0
   762
					display->SetRotationL(*window.iWindow, aRotation, iCropRegion);
sl@0
   763
sl@0
   764
					if (iSubtitleUtility)
sl@0
   765
						{
sl@0
   766
						TMMFSubtitleWindowConfig config;
sl@0
   767
						GetSubtitleConfigFromWindowData(window, config);
sl@0
   768
sl@0
   769
						iSubtitleUtility->UpdateSubtitleConfig(config);
sl@0
   770
						}
sl@0
   771
					}
sl@0
   772
				}
sl@0
   773
#else
sl@0
   774
sl@0
   775
			iActiveDisplays[i]->SetRotationL(aRotation, iCropRegion);
sl@0
   776
#endif//SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
   777
			}
sl@0
   778
sl@0
   779
		iGlobalRotation = aRotation;
sl@0
   780
sl@0
   781
		}
sl@0
   782
#else 
sl@0
   783
	User::LeaveIfError(iVideoPlayControllerCustomCommands.SetRotation(aRotation));
sl@0
   784
#endif // SYMBIAN_BUILD_GCE
sl@0
   785
sl@0
   786
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL--");
sl@0
   787
	}
sl@0
   788
sl@0
   789
TVideoRotation CVideoPlayerUtility::CBody::RotationL() const
sl@0
   790
	{
sl@0
   791
	TVideoRotation rot = EVideoRotationNone;
sl@0
   792
#ifdef SYMBIAN_BUILD_GCE
sl@0
   793
	if (!iGraphicsSurfaceSupported)
sl@0
   794
		{		
sl@0
   795
		User::LeaveIfError(iVideoPlayControllerCustomCommands.GetRotation(rot));		
sl@0
   796
		}
sl@0
   797
	else 
sl@0
   798
		{
sl@0
   799
		// Rotation setting is not retrieved from controller when graphics surfaces are used.
sl@0
   800
		rot = iGlobalRotation;
sl@0
   801
		}
sl@0
   802
#else
sl@0
   803
	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetRotation(rot));
sl@0
   804
#endif // SYMBIAN_BUILD_GCE
sl@0
   805
	return rot;
sl@0
   806
	}
sl@0
   807
sl@0
   808
void CVideoPlayerUtility::CBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, TBool aAntiAliasFiltering)
sl@0
   809
	{
sl@0
   810
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL");
sl@0
   811
    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f, aAntiAliasFiltering %d", aWidthPercentage, aHeightPercentage, aAntiAliasFiltering);
sl@0
   812
sl@0
   813
#ifdef SYMBIAN_BUILD_GCE
sl@0
   814
	if (!iGraphicsSurfaceSupported)
sl@0
   815
		{
sl@0
   816
		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
sl@0
   817
		}
sl@0
   818
	else
sl@0
   819
		{
sl@0
   820
		// Scale factor  setting is not sent to controller when graphics surfaces are used.
sl@0
   821
		// If the surface has been created, perform scale factor with the help of graphics surfaces.
sl@0
   822
		iAntiAliasFiltering = aAntiAliasFiltering;
sl@0
   823
		iGlobalScaleWidth = aWidthPercentage;
sl@0
   824
		iGlobalScaleHeight = aHeightPercentage;
sl@0
   825
		iGlobalAutoScaleType = EAutoScaleNone;
sl@0
   826
sl@0
   827
		TInt count = iActiveDisplays.Count();
sl@0
   828
		
sl@0
   829
		for (TInt i = 0; i < count; ++i)
sl@0
   830
			{
sl@0
   831
			iActiveDisplays[i]->SetScaleFactorL(aWidthPercentage, aHeightPercentage, iCropRegion);
sl@0
   832
			}
sl@0
   833
		}
sl@0
   834
#else
sl@0
   835
	User::LeaveIfError(iVideoPlayControllerCustomCommands.SetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
sl@0
   836
#endif	// SYMBIAN_BUILD_GCE
sl@0
   837
sl@0
   838
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL--");
sl@0
   839
	}
sl@0
   840
sl@0
   841
void CVideoPlayerUtility::CBody::GetScaleFactorL(TReal32& aWidthPercentage, TReal32& aHeightPercentage, TBool& aAntiAliasFiltering) const
sl@0
   842
	{
sl@0
   843
#ifdef SYMBIAN_BUILD_GCE
sl@0
   844
	if (!iGraphicsSurfaceSupported)
sl@0
   845
		{
sl@0
   846
		User::LeaveIfError(iVideoPlayControllerCustomCommands.GetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
sl@0
   847
		}
sl@0
   848
	else
sl@0
   849
		{
sl@0
   850
		// Scale factor setting is not retrieved from controller when graphics surfaces are used.
sl@0
   851
		
sl@0
   852
		aWidthPercentage = iGlobalScaleWidth;
sl@0
   853
		aHeightPercentage = iGlobalScaleHeight;	
sl@0
   854
		
sl@0
   855
		aAntiAliasFiltering = iAntiAliasFiltering;
sl@0
   856
		}
sl@0
   857
#else
sl@0
   858
	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));	
sl@0
   859
#endif // SYMBIAN_BUILD_GCE
sl@0
   860
	}
sl@0
   861
sl@0
   862
void CVideoPlayerUtility::CBody::SetCropRegionL(const TRect& aCropRegion)
sl@0
   863
	{
sl@0
   864
#ifdef SYMBIAN_BUILD_GCE
sl@0
   865
	if (!iGraphicsSurfaceSupported)
sl@0
   866
		{
sl@0
   867
		User::LeaveIfError(iVideoPlayControllerCustomCommands.SetCropRegion(aCropRegion));
sl@0
   868
		}
sl@0
   869
	else
sl@0
   870
		{
sl@0
   871
		// Crop region setting is not sent to controller when graphics surfaces are used.
sl@0
   872
		// If the surface has been created, perform crop region with the help of graphics surfaces;
sl@0
   873
		// otherwise, just store the crop region info.
sl@0
   874
		if (aCropRegion != iCropRegion)
sl@0
   875
			{
sl@0
   876
			iCropRegion = aCropRegion;
sl@0
   877
			User::LeaveIfError(SetAllBackgroundSurfaces());
sl@0
   878
			}
sl@0
   879
		}
sl@0
   880
#else
sl@0
   881
	User::LeaveIfError(iVideoPlayControllerCustomCommands.SetCropRegion(aCropRegion));
sl@0
   882
#endif // SYMBIAN_BUILD_GCE
sl@0
   883
	}
sl@0
   884
sl@0
   885
void CVideoPlayerUtility::CBody::GetCropRegionL(TRect& aCropRegion) const
sl@0
   886
	{
sl@0
   887
#ifdef SYMBIAN_BUILD_GCE
sl@0
   888
	if (!iGraphicsSurfaceSupported )
sl@0
   889
		{
sl@0
   890
		User::LeaveIfError(iVideoPlayControllerCustomCommands.GetCropRegion(aCropRegion));
sl@0
   891
		}
sl@0
   892
	else
sl@0
   893
		{
sl@0
   894
		// Crop rectangle setting is not retrieved from controller when graphics surfaces are used.
sl@0
   895
		aCropRegion = iCropRegion;
sl@0
   896
		}
sl@0
   897
#else
sl@0
   898
	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetCropRegion(aCropRegion));
sl@0
   899
#endif // SYMBIAN_BUILD_GCE
sl@0
   900
	}
sl@0
   901
sl@0
   902
void CVideoPlayerUtility::CBody::Prepare()
sl@0
   903
	{
sl@0
   904
	TInt error = iVideoPlayControllerCustomCommands.Prepare();
sl@0
   905
	if (error)
sl@0
   906
		iObserver.MvpuoPrepareComplete(error);
sl@0
   907
	}
sl@0
   908
sl@0
   909
const TDesC8& CVideoPlayerUtility::CBody::VideoFormatMimeType() const
sl@0
   910
	{
sl@0
   911
	TPtr8 des = iMimeType->Des();
sl@0
   912
	TInt err = iVideoControllerCustomCommands.GetVideoMimeType(des);
sl@0
   913
	if (!err)
sl@0
   914
		return *iMimeType;
sl@0
   915
	else
sl@0
   916
		return KNullDesC8;
sl@0
   917
	}
sl@0
   918
											 
sl@0
   919
void CVideoPlayerUtility::CBody::RegisterForVideoLoadingNotification(MVideoLoadingObserver& aObserver)
sl@0
   920
	{
sl@0
   921
	iVideoLoadingObserver = &aObserver;
sl@0
   922
	}
sl@0
   923
sl@0
   924
TInt CVideoPlayerUtility::CBody::NumberOfMetaDataEntriesL() const
sl@0
   925
	{
sl@0
   926
	TInt num = 0;
sl@0
   927
	User::LeaveIfError(iController.GetNumberOfMetaDataEntries(num));
sl@0
   928
	return num;
sl@0
   929
	}
sl@0
   930
sl@0
   931
sl@0
   932
CMMFMetaDataEntry* CVideoPlayerUtility::CBody::MetaDataEntryL(TInt aMetaDataIndex) const
sl@0
   933
	{
sl@0
   934
	return iController.GetMetaDataEntryL(aMetaDataIndex);
sl@0
   935
	}
sl@0
   936
sl@0
   937
void CVideoPlayerUtility::CBody::SetPriorityL(TInt aPriority, TInt aPref)
sl@0
   938
	{
sl@0
   939
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPriorityL++");
sl@0
   940
    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::SetPriorityL - aPriority %d, aPref %d", aPriority, aPref);
sl@0
   941
sl@0
   942
    iPrioritySettings.iPref = aPref;
sl@0
   943
	iPrioritySettings.iPriority = aPriority;
sl@0
   944
sl@0
   945
	TInt err = iController.SetPrioritySettings(iPrioritySettings);
sl@0
   946
	if ((err == KErrNone) || (err == KErrNotReady))
sl@0
   947
		{
sl@0
   948
		iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
sl@0
   949
		}
sl@0
   950
	else
sl@0
   951
		{
sl@0
   952
		User::Leave(err);
sl@0
   953
		}
sl@0
   954
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPriorityL--");
sl@0
   955
	}
sl@0
   956
sl@0
   957
void CVideoPlayerUtility::CBody::PriorityL(TInt & aPriority, TMdaPriorityPreference &aPref) const 
sl@0
   958
	{
sl@0
   959
	aPriority = iPrioritySettings.iPriority;
sl@0
   960
	aPref = TMdaPriorityPreference(iPrioritySettings.iPref);
sl@0
   961
	}
sl@0
   962
sl@0
   963
sl@0
   964
void CVideoPlayerUtility::CBody::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
sl@0
   965
	{
sl@0
   966
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPositionL++");
sl@0
   967
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetPositionL - aPosition %ld", aPosition.Int64());
sl@0
   968
	User::LeaveIfError(iController.SetPosition(aPosition));
sl@0
   969
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPositionL--");
sl@0
   970
	}
sl@0
   971
sl@0
   972
sl@0
   973
TTimeIntervalMicroSeconds CVideoPlayerUtility::CBody::DurationL() const
sl@0
   974
	{
sl@0
   975
	TTimeIntervalMicroSeconds duration;
sl@0
   976
	User::LeaveIfError(iController.GetDuration(duration));
sl@0
   977
	return duration;
sl@0
   978
	}
sl@0
   979
sl@0
   980
TTimeIntervalMicroSeconds CVideoPlayerUtility::CBody::PositionL() const
sl@0
   981
	{
sl@0
   982
	TTimeIntervalMicroSeconds position;
sl@0
   983
	User::LeaveIfError(iController.GetPosition(position));
sl@0
   984
	return position;
sl@0
   985
	}
sl@0
   986
sl@0
   987
TInt CVideoPlayerUtility::CBody::MaxVolume() const
sl@0
   988
	{
sl@0
   989
	TInt maxVol = 0;
sl@0
   990
	iAudioPlayDeviceCustomCommands.GetMaxVolume(maxVol);
sl@0
   991
	return maxVol;
sl@0
   992
	}
sl@0
   993
sl@0
   994
void CVideoPlayerUtility::CBody::GetFrameL(TDisplayMode aDisplayMode, TBool aUseIntentAPI, TIntent aIntent)
sl@0
   995
	{
sl@0
   996
	delete iFrameBitmap;
sl@0
   997
	iFrameBitmap = NULL;
sl@0
   998
	iFrameBitmap = new (ELeave) CFbsBitmap;
sl@0
   999
	User::LeaveIfError(iFrameBitmap->Create(TSize(0,0),aDisplayMode));
sl@0
  1000
sl@0
  1001
	iFrameCallback->SetFrame(*iFrameBitmap);
sl@0
  1002
sl@0
  1003
	if (aUseIntentAPI)
sl@0
  1004
		{
sl@0
  1005
		iVideoDRMExtCustomCommands.GetFrame(*iFrameBitmap, aIntent, iFrameCallback->ActiveStatus());
sl@0
  1006
		}
sl@0
  1007
	else
sl@0
  1008
		{
sl@0
  1009
		iVideoPlayControllerCustomCommands.GetFrame(*iFrameBitmap, iFrameCallback->ActiveStatus());
sl@0
  1010
		}
sl@0
  1011
	}
sl@0
  1012
sl@0
  1013
MMMFDRMCustomCommand* CVideoPlayerUtility::CBody::GetDRMCustomCommand()
sl@0
  1014
	{
sl@0
  1015
	// XXX: check controller supports MMMFDRMCustomCommandImplementor
sl@0
  1016
	TInt error = iDRMCustomCommands.EvaluateIntent(ContentAccess::EPeek);
sl@0
  1017
	if (error==KErrNone)
sl@0
  1018
		{
sl@0
  1019
		return static_cast<MMMFDRMCustomCommand*>(&iDRMCustomCommands);
sl@0
  1020
		}
sl@0
  1021
	else
sl@0
  1022
		{
sl@0
  1023
		return NULL;
sl@0
  1024
		}
sl@0
  1025
	}
sl@0
  1026
	
sl@0
  1027
TInt CVideoPlayerUtility::CBody::VideoBitRateL() const
sl@0
  1028
	{
sl@0
  1029
	TInt bitRate;
sl@0
  1030
	User::LeaveIfError(iVideoControllerCustomCommands.GetVideoBitRate(bitRate));
sl@0
  1031
	return bitRate;
sl@0
  1032
	}
sl@0
  1033
sl@0
  1034
TInt CVideoPlayerUtility::CBody::AudioBitRateL() const
sl@0
  1035
	{
sl@0
  1036
	TInt bitRate;
sl@0
  1037
	User::LeaveIfError(iVideoControllerCustomCommands.GetAudioBitRate(bitRate));
sl@0
  1038
	return bitRate;
sl@0
  1039
	}
sl@0
  1040
sl@0
  1041
TBool CVideoPlayerUtility::CBody::AudioEnabledL() const
sl@0
  1042
	{
sl@0
  1043
	TBool enabled;
sl@0
  1044
	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetAudioEnabled(enabled));
sl@0
  1045
	return enabled;
sl@0
  1046
	}
sl@0
  1047
	
sl@0
  1048
	
sl@0
  1049
void CVideoPlayerUtility::CBody::RefreshFrameL()
sl@0
  1050
	{
sl@0
  1051
	User::LeaveIfError(iVideoPlayControllerCustomCommands.RefreshFrame());
sl@0
  1052
	}
sl@0
  1053
sl@0
  1054
TFourCC CVideoPlayerUtility::CBody::AudioTypeL() const
sl@0
  1055
	{
sl@0
  1056
	TFourCC codec;
sl@0
  1057
	User::LeaveIfError(iVideoControllerCustomCommands.GetAudioCodec(codec));
sl@0
  1058
	return codec;
sl@0
  1059
	}
sl@0
  1060
sl@0
  1061
sl@0
  1062
void CVideoPlayerUtility::CBody::HandleEvent(const TMMFEvent& aEvent)
sl@0
  1063
	{
sl@0
  1064
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::HandleEvent++");
sl@0
  1065
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::HandleEvent - Event type 0x%X", aEvent.iEventType);
sl@0
  1066
sl@0
  1067
    if (aEvent.iEventType == KMMFEventCategoryVideoOpenComplete)
sl@0
  1068
		{
sl@0
  1069
		// if we haven't had a MfaocComplete() callback yet,
sl@0
  1070
		// we need to delay the call back to the client
sl@0
  1071
		// because the source/sink will not have been opened yet.
sl@0
  1072
		iEventOpenReceived = ETrue;
sl@0
  1073
		if (iOpenError == KErrNone)
sl@0
  1074
			iOpenError = aEvent.iErrorCode;
sl@0
  1075
		if (iCallbackOpenReceived)
sl@0
  1076
			iObserver.MvpuoOpenComplete(aEvent.iErrorCode);
sl@0
  1077
		}
sl@0
  1078
	else if (aEvent.iEventType == KMMFEventCategoryVideoPrepareComplete)
sl@0
  1079
		{
sl@0
  1080
		iObserver.MvpuoPrepareComplete(aEvent.iErrorCode);
sl@0
  1081
		}
sl@0
  1082
	else if (aEvent.iEventType == KMMFEventCategoryPlaybackComplete)
sl@0
  1083
		{
sl@0
  1084
		iObserver.MvpuoPlayComplete(aEvent.iErrorCode);
sl@0
  1085
		}
sl@0
  1086
	else if (aEvent.iEventType == KMMFEventCategoryVideoLoadingStarted)
sl@0
  1087
		{
sl@0
  1088
		if (iVideoLoadingObserver)
sl@0
  1089
			iVideoLoadingObserver->MvloLoadingStarted();
sl@0
  1090
		}
sl@0
  1091
	else if (aEvent.iEventType == KMMFEventCategoryVideoLoadingComplete)
sl@0
  1092
		{
sl@0
  1093
		if (iVideoLoadingObserver)
sl@0
  1094
			iVideoLoadingObserver->MvloLoadingComplete();
sl@0
  1095
		}
sl@0
  1096
	else if(aEvent.iEventType == KMMFEventCategoryAudioResourceAvailable)
sl@0
  1097
		{
sl@0
  1098
		if(iAudioResourceNotificationCallBack != NULL)
sl@0
  1099
			{
sl@0
  1100
			TBuf8<TMMFAudioConfig::KNotificationDataBufferSize> notificationData;
sl@0
  1101
			if (KErrNone != iNotificationRegistrationCommands.GetResourceNotificationData(aEvent.iEventType, notificationData))
sl@0
  1102
				{
sl@0
  1103
				notificationData.SetLength(0);
sl@0
  1104
				}
sl@0
  1105
			iAudioResourceNotificationCallBack->MarncResourceAvailable(aEvent.iEventType, notificationData);	
sl@0
  1106
			}
sl@0
  1107
		}
sl@0
  1108
#ifdef SYMBIAN_BUILD_GCE
sl@0
  1109
	else if(aEvent.iEventType == KMMFEventCategoryVideoSurfaceCreated)
sl@0
  1110
		{
sl@0
  1111
		TInt error = SurfaceCreated();
sl@0
  1112
			
sl@0
  1113
		if (error != KErrNone)	
sl@0
  1114
			{
sl@0
  1115
			// Send error to the client
sl@0
  1116
			TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
sl@0
  1117
			iObserver.MvpuoEvent(generalError);	
sl@0
  1118
			}
sl@0
  1119
		}
sl@0
  1120
	else if(aEvent.iEventType == KMMFEventCategoryVideoSurfaceParametersChanged)
sl@0
  1121
		{
sl@0
  1122
		TInt error = SurfaceParametersChanged();
sl@0
  1123
				
sl@0
  1124
		if (error != KErrNone)	
sl@0
  1125
			{
sl@0
  1126
			// Send error to the client
sl@0
  1127
			TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
sl@0
  1128
			iObserver.MvpuoEvent(generalError);	
sl@0
  1129
			}
sl@0
  1130
		}		
sl@0
  1131
	else if(aEvent.iEventType == KMMFEventCategoryVideoRemoveSurface)
sl@0
  1132
		{
sl@0
  1133
		// Check surface is created
sl@0
  1134
		TInt error = RemoveSurface(ETrue);
sl@0
  1135
			
sl@0
  1136
		if (error != KErrNone)
sl@0
  1137
			{
sl@0
  1138
			// Send error to the client
sl@0
  1139
			TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
sl@0
  1140
			iObserver.MvpuoEvent(generalError);	
sl@0
  1141
			}
sl@0
  1142
		}
sl@0
  1143
#endif // SYMBIAN_BUILD_GCE	
sl@0
  1144
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1145
	else if(aEvent.iEventType == KMMFEventCategoryVideoSubtitleCrpReady)
sl@0
  1146
		{
sl@0
  1147
		if (iSubtitleUtility)
sl@0
  1148
			{
sl@0
  1149
			// subtitle has not been disabled before event arrive
sl@0
  1150
			RWindow* window = FindWindowWithWsHandle(iActiveDisplays, aEvent.iErrorCode);
sl@0
  1151
			if (window)
sl@0
  1152
				{
sl@0
  1153
				// window has not been removed before event arrive
sl@0
  1154
				iSubtitleUtility->HandleCrpReady(*window);
sl@0
  1155
				}
sl@0
  1156
			}
sl@0
  1157
		}
sl@0
  1158
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1159
	else 
sl@0
  1160
		// Pass on all unrecognised events to the client
sl@0
  1161
		iObserver.MvpuoEvent(aEvent);
sl@0
  1162
sl@0
  1163
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::HandleEvent--");
sl@0
  1164
	}
sl@0
  1165
sl@0
  1166
#ifdef SYMBIAN_BUILD_GCE
sl@0
  1167
TInt CVideoPlayerUtility::CBody::SurfaceCreated()
sl@0
  1168
	{
sl@0
  1169
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceCreated++");
sl@0
  1170
sl@0
  1171
    TInt count = iActiveDisplays.Count();
sl@0
  1172
	TBool replaceSurface = !(iSurfaceId.IsNull());
sl@0
  1173
	TSurfaceId oldSurfaceId(iSurfaceId);
sl@0
  1174
	
sl@0
  1175
	// first remove surface if one already in use
sl@0
  1176
	if(replaceSurface)
sl@0
  1177
		{
sl@0
  1178
		for (TInt i = 0; i < count; i++)
sl@0
  1179
			{
sl@0
  1180
			CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
sl@0
  1181
			display->RemoveSurface(EFalse);
sl@0
  1182
			}
sl@0
  1183
		iSurfaceId = TSurfaceId::CreateNullId();
sl@0
  1184
		}
sl@0
  1185
	
sl@0
  1186
	TSurfaceId surfaceId;
sl@0
  1187
	TRect cropRect;
sl@0
  1188
	TVideoAspectRatio aspectRatio;
sl@0
  1189
	
sl@0
  1190
	TInt error = iVideoPlaySurfaceSupportCustomCommands.GetSurfaceParameters(surfaceId, 
sl@0
  1191
										cropRect, 
sl@0
  1192
										aspectRatio);
sl@0
  1193
	if(error != KErrNone)
sl@0
  1194
		{
sl@0
  1195
		if(replaceSurface)
sl@0
  1196
				{
sl@0
  1197
				// ignore error
sl@0
  1198
				iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(oldSurfaceId);
sl@0
  1199
				}
sl@0
  1200
		return error;
sl@0
  1201
		}
sl@0
  1202
	
sl@0
  1203
	// loop through all displays, if any fail continue and report error later
sl@0
  1204
	TInt error2;
sl@0
  1205
	for (TInt i = 0; i < count; ++i)
sl@0
  1206
		{
sl@0
  1207
		error2 = iActiveDisplays[i]->SurfaceCreated(surfaceId, cropRect, aspectRatio, iCropRegion);
sl@0
  1208
		if(error2 != KErrNone)
sl@0
  1209
			{
sl@0
  1210
			error = error2;
sl@0
  1211
			}
sl@0
  1212
		}
sl@0
  1213
	
sl@0
  1214
	// now store surface details
sl@0
  1215
	iSurfaceId = surfaceId;
sl@0
  1216
	iSurfaceCropRect = cropRect;
sl@0
  1217
	iAspectRatio = aspectRatio;
sl@0
  1218
	
sl@0
  1219
	// if surface already existed tell video adaptation it is no longer in use. Video adaptation
sl@0
  1220
	// will remove the surface when it receives this call therefore the following code must be done at the
sl@0
  1221
	// end of this function.
sl@0
  1222
	if (replaceSurface)
sl@0
  1223
        {
sl@0
  1224
        error2 = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(oldSurfaceId);
sl@0
  1225
        if (error2 != KErrNone)
sl@0
  1226
            {
sl@0
  1227
            error = error2;
sl@0
  1228
            }
sl@0
  1229
        }
sl@0
  1230
sl@0
  1231
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceCreated--");
sl@0
  1232
	return error;
sl@0
  1233
	}
sl@0
  1234
sl@0
  1235
TInt CVideoPlayerUtility::CBody::SurfaceParametersChanged()
sl@0
  1236
	{
sl@0
  1237
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceParametersChanged++");
sl@0
  1238
	if (iSurfaceId.IsNull())
sl@0
  1239
		{
sl@0
  1240
		return KErrNotSupported;
sl@0
  1241
		}
sl@0
  1242
	
sl@0
  1243
	TSurfaceId surfaceId;
sl@0
  1244
	TRect cropRect;
sl@0
  1245
	TVideoAspectRatio aspectRatio;
sl@0
  1246
	
sl@0
  1247
	TInt error = iVideoPlaySurfaceSupportCustomCommands.GetSurfaceParameters(surfaceId, 
sl@0
  1248
										cropRect, 
sl@0
  1249
										aspectRatio);
sl@0
  1250
	if (error != KErrNone)
sl@0
  1251
		{
sl@0
  1252
		return error;
sl@0
  1253
		}
sl@0
  1254
	
sl@0
  1255
	if (iSurfaceId != surfaceId)
sl@0
  1256
		{
sl@0
  1257
		return KErrInUse;
sl@0
  1258
		}
sl@0
  1259
sl@0
  1260
	TInt count = iActiveDisplays.Count();
sl@0
  1261
	TInt error2 = KErrNone;
sl@0
  1262
	for (TInt i = 0; i < count; ++i)
sl@0
  1263
		{
sl@0
  1264
		error2 = iActiveDisplays[i]->SurfaceParametersChanged(surfaceId, cropRect, aspectRatio);
sl@0
  1265
		
sl@0
  1266
		// Save the error for the first failure only
sl@0
  1267
		if ((error2 != KErrNone) && (error == KErrNone))
sl@0
  1268
			{
sl@0
  1269
			error = error2;
sl@0
  1270
			}
sl@0
  1271
		}
sl@0
  1272
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SurfaceParametersChanged-- - Error %d", error);
sl@0
  1273
    return error;
sl@0
  1274
	}
sl@0
  1275
		
sl@0
  1276
TInt CVideoPlayerUtility::CBody::SetAllBackgroundSurfaces()
sl@0
  1277
	{
sl@0
  1278
	TInt count = iActiveDisplays.Count();
sl@0
  1279
	TInt err = KErrNone;
sl@0
  1280
	
sl@0
  1281
	for (TInt i = 0; i < count; ++i)
sl@0
  1282
		{
sl@0
  1283
		CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
sl@0
  1284
		err = display->RedrawWindows(iCropRegion);
sl@0
  1285
			
sl@0
  1286
		if (err != KErrNone)
sl@0
  1287
			{
sl@0
  1288
			break;
sl@0
  1289
			}
sl@0
  1290
		}
sl@0
  1291
	return err;
sl@0
  1292
	}
sl@0
  1293
sl@0
  1294
TInt CVideoPlayerUtility::CBody::RemoveSurface(TBool aControllerEvent)
sl@0
  1295
	{
sl@0
  1296
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveSurface++");
sl@0
  1297
	if (iSurfaceId.IsNull())
sl@0
  1298
		{
sl@0
  1299
		return KErrNotFound;
sl@0
  1300
		}
sl@0
  1301
	
sl@0
  1302
	TInt count = iActiveDisplays.Count();
sl@0
  1303
	for (TInt i = 0; i < count; i++)
sl@0
  1304
		{
sl@0
  1305
		iActiveDisplays[i]->RemoveSurface(aControllerEvent);
sl@0
  1306
		}
sl@0
  1307
	
sl@0
  1308
	TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iSurfaceId);
sl@0
  1309
sl@0
  1310
	iSurfaceId = TSurfaceId::CreateNullId();
sl@0
  1311
	
sl@0
  1312
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveSurface-- - Error %d", error);
sl@0
  1313
	return error;
sl@0
  1314
	}
sl@0
  1315
	
sl@0
  1316
#endif // SYMBIAN_BUILD_GCE
sl@0
  1317
sl@0
  1318
void CVideoPlayerUtility::CBody::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
sl@0
  1319
	{
sl@0
  1320
	if (iControllerOpen)
sl@0
  1321
		{
sl@0
  1322
		iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EAbortDSA);
sl@0
  1323
		iDirectScreenAccessAbort = ETrue;
sl@0
  1324
		}
sl@0
  1325
	}
sl@0
  1326
sl@0
  1327
void CVideoPlayerUtility::CBody::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/) 
sl@0
  1328
	{
sl@0
  1329
	__ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument)); // should always be valid if we have a callback from it
sl@0
  1330
	TRAPD( err, iDirectScreenAccess->StartL());
sl@0
  1331
sl@0
  1332
	if (iControllerOpen)
sl@0
  1333
		{
sl@0
  1334
		if (err == KErrNone)
sl@0
  1335
			{
sl@0
  1336
			iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion());
sl@0
  1337
			iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EResumeDSA);
sl@0
  1338
			}
sl@0
  1339
		}
sl@0
  1340
	}
sl@0
  1341
sl@0
  1342
TInt CVideoPlayerUtility::CBody::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom)
sl@0
  1343
	{
sl@0
  1344
	return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom);
sl@0
  1345
	}
sl@0
  1346
	
sl@0
  1347
TInt CVideoPlayerUtility::CBody::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2)
sl@0
  1348
	{
sl@0
  1349
	return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2);
sl@0
  1350
	}
sl@0
  1351
	
sl@0
  1352
void CVideoPlayerUtility::CBody::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus)
sl@0
  1353
	{
sl@0
  1354
	iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom, aStatus);
sl@0
  1355
	}
sl@0
  1356
	
sl@0
  1357
void CVideoPlayerUtility::CBody::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus)
sl@0
  1358
	{
sl@0
  1359
	iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aStatus);
sl@0
  1360
	}
sl@0
  1361
	
sl@0
  1362
void CVideoPlayerUtility::CBody::SetVideoFrameRateL(TReal32 aFramesPerSecond)
sl@0
  1363
	{
sl@0
  1364
	User::LeaveIfError(iVideoControllerCustomCommands.SetFrameRate(aFramesPerSecond));
sl@0
  1365
	}
sl@0
  1366
sl@0
  1367
const CMMFControllerImplementationInformation& CVideoPlayerUtility::CBody::ControllerImplementationInformationL()
sl@0
  1368
	{
sl@0
  1369
	if (!iControllerImplementationInformation)
sl@0
  1370
		{
sl@0
  1371
		if (iControllerUid==KNullUid)
sl@0
  1372
			User::Leave(KErrNotReady);
sl@0
  1373
		iControllerImplementationInformation = CMMFControllerImplementationInformation::NewL(iControllerUid);
sl@0
  1374
		}
sl@0
  1375
	return *iControllerImplementationInformation;
sl@0
  1376
	}
sl@0
  1377
	
sl@0
  1378
void CVideoPlayerUtility::CBody::GetVideoLoadingProgressL(TInt& aPercentageProgress)
sl@0
  1379
	{
sl@0
  1380
	User::LeaveIfError(iVideoPlayControllerCustomCommands.GetLoadingProgress(aPercentageProgress));
sl@0
  1381
	}
sl@0
  1382
sl@0
  1383
void CVideoPlayerUtility::CBody::StopDirectScreenAccessL()
sl@0
  1384
	{
sl@0
  1385
#ifdef SYMBIAN_BUILD_GCE
sl@0
  1386
	if (iUsingVPU2)
sl@0
  1387
		{
sl@0
  1388
		User::Leave(KErrNotSupported);
sl@0
  1389
		}
sl@0
  1390
sl@0
  1391
	if (!iGraphicsSurfaceSupported)
sl@0
  1392
		{
sl@0
  1393
		__ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument));
sl@0
  1394
		iDirectScreenAccess->Cancel();
sl@0
  1395
		AbortNow(RDirectScreenAccess::ETerminateCancel);
sl@0
  1396
		}
sl@0
  1397
#else
sl@0
  1398
	__ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument));
sl@0
  1399
	iDirectScreenAccess->Cancel();
sl@0
  1400
	AbortNow(RDirectScreenAccess::ETerminateCancel);
sl@0
  1401
#endif // SYMBIAN_BUILD_GCE
sl@0
  1402
	}
sl@0
  1403
	
sl@0
  1404
void CVideoPlayerUtility::CBody::StartDirectScreenAccessL()
sl@0
  1405
	{
sl@0
  1406
#ifdef SYMBIAN_BUILD_GCE
sl@0
  1407
	if (iUsingVPU2)
sl@0
  1408
		{
sl@0
  1409
		User::Leave(KErrNotSupported);
sl@0
  1410
		}
sl@0
  1411
sl@0
  1412
	if (!iGraphicsSurfaceSupported)
sl@0
  1413
		{
sl@0
  1414
		// ETerminateCancel is a dummy value that is ignored by Restart()
sl@0
  1415
		Restart(RDirectScreenAccess::ETerminateCancel);
sl@0
  1416
		}
sl@0
  1417
#else
sl@0
  1418
	// ETerminateCancel is a dummy value that is ignored by Restart()
sl@0
  1419
	Restart(RDirectScreenAccess::ETerminateCancel);
sl@0
  1420
#endif  // SYMBIAN_BUILD_GCE
sl@0
  1421
	}
sl@0
  1422
sl@0
  1423
//registers for notification when audio resource is available.
sl@0
  1424
TInt CVideoPlayerUtility::CBody::RegisterAudioResourceNotification( MMMFAudioResourceNotificationCallback& aCallback, 
sl@0
  1425
																	TUid aNotificationEventUid, 
sl@0
  1426
																	const TDesC8& aNotificationRegistrationData)
sl@0
  1427
	{
sl@0
  1428
	//if not valid notification event id, return;
sl@0
  1429
	if(aNotificationEventUid != KMMFEventCategoryAudioResourceAvailable)
sl@0
  1430
		{
sl@0
  1431
		return KErrNotSupported;
sl@0
  1432
		}
sl@0
  1433
		
sl@0
  1434
	iAudioResourceNotificationCallBack = &aCallback;
sl@0
  1435
	TInt err = iNotificationRegistrationCommands.RegisterAsClient(aNotificationEventUid, aNotificationRegistrationData);
sl@0
  1436
	if(err == KErrNotReady)
sl@0
  1437
		{
sl@0
  1438
		//save the request - so that registration can be attempted on play
sl@0
  1439
		iArnEventHolder = 	aNotificationEventUid;
sl@0
  1440
		iNotificationDataHolder = aNotificationRegistrationData;
sl@0
  1441
		return KErrNone;
sl@0
  1442
		}
sl@0
  1443
	iArnEventHolder = KNullUid;
sl@0
  1444
	iNotificationDataHolder = KNullDesC8;
sl@0
  1445
	return err;
sl@0
  1446
	}
sl@0
  1447
sl@0
  1448
//Cancels the registration for audio resource notification.
sl@0
  1449
TInt CVideoPlayerUtility::CBody::CancelRegisterAudioResourceNotification(TUid aNotificationEventId)
sl@0
  1450
	{
sl@0
  1451
	//if not valid notification event id, return;
sl@0
  1452
	if(aNotificationEventId != KMMFEventCategoryAudioResourceAvailable)
sl@0
  1453
		{
sl@0
  1454
		return KErrNotSupported;
sl@0
  1455
		}
sl@0
  1456
	TInt err = iNotificationRegistrationCommands.CancelRegisterAsClient(aNotificationEventId);
sl@0
  1457
	if(err == KErrNotReady)
sl@0
  1458
		{
sl@0
  1459
		if(iArnEventHolder == KNullUid)	
sl@0
  1460
			{
sl@0
  1461
			return KErrCancel;
sl@0
  1462
			}
sl@0
  1463
		//iArnEventHolder has data to re-attempt registration ;
sl@0
  1464
		//but reattempt is not made(which is done in play);hence return KErrNone
sl@0
  1465
		iArnEventHolder = KNullUid;
sl@0
  1466
		iNotificationDataHolder = KNullDesC8;
sl@0
  1467
		return KErrNone;
sl@0
  1468
		}
sl@0
  1469
	return err;
sl@0
  1470
	}
sl@0
  1471
sl@0
  1472
//Waits for the client to resume the play even after the default timer expires.
sl@0
  1473
TInt CVideoPlayerUtility::CBody::WillResumePlay()
sl@0
  1474
	{
sl@0
  1475
	return iNotificationRegistrationCommands.WillResumePlay();
sl@0
  1476
	}
sl@0
  1477
sl@0
  1478
// This method will fail with KErrNotSupported when using CVideoPlayerUtility2, otherwise
sl@0
  1479
// set the screen number.
sl@0
  1480
TInt CVideoPlayerUtility::CBody::SetInitScreenNumber(TInt aScreenNumber)
sl@0
  1481
	{
sl@0
  1482
#ifdef SYMBIAN_BUILD_GCE
sl@0
  1483
	// If the method is called from CVideoPlayerUtility2, return KErrNotSupport
sl@0
  1484
	if (iUsingVPU2)
sl@0
  1485
		{
sl@0
  1486
		return KErrNotSupported;
sl@0
  1487
		}
sl@0
  1488
#endif
sl@0
  1489
		
sl@0
  1490
#ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
sl@0
  1491
	iScreenNumber = aScreenNumber;
sl@0
  1492
	return KErrNone;
sl@0
  1493
#else
sl@0
  1494
	aScreenNumber = aScreenNumber;//added to remove the warning
sl@0
  1495
	return KErrNotSupported;
sl@0
  1496
#endif
sl@0
  1497
	}
sl@0
  1498
sl@0
  1499
#ifdef SYMBIAN_BUILD_GCE
sl@0
  1500
//-------------------------------------------------------------------------------
sl@0
  1501
sl@0
  1502
void CVideoPlayerUtility::CBody::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, 
sl@0
  1503
							RWindow& aWindow, const TRect& aVideoExtent, 
sl@0
  1504
							const TRect& aWindowClipRect)
sl@0
  1505
	{
sl@0
  1506
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL++");
sl@0
  1507
    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::AddDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
sl@0
  1508
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
  1509
    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);
sl@0
  1510
    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
sl@0
  1511
    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
sl@0
  1512
sl@0
  1513
    // set window and get display ID for the window
sl@0
  1514
	TRect windowRect = TRect(aWindow.Size()); 
sl@0
  1515
	
sl@0
  1516
	// Check the rectangle is contained completely within the window
sl@0
  1517
	if (!RectContains(windowRect, aWindowClipRect))
sl@0
  1518
		{
sl@0
  1519
		// NOTE: TRect::Contains() is not used for comparison here as point located on the right hand 
sl@0
  1520
		//       side or bottom is considered to be outside the rectangle, which is not the desirable 
sl@0
  1521
		//       behaviour in this case
sl@0
  1522
		User::Leave(KErrArgument);
sl@0
  1523
		}
sl@0
  1524
		
sl@0
  1525
	DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, aWindowClipRect, aVideoExtent, &aWindow);
sl@0
  1526
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL--");
sl@0
  1527
	}
sl@0
  1528
	
sl@0
  1529
void CVideoPlayerUtility::CBody::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
sl@0
  1530
	{
sl@0
  1531
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL++");
sl@0
  1532
    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::AddDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
sl@0
  1533
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
  1534
    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);
sl@0
  1535
sl@0
  1536
    DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, TRect(aWindow.Size()), TRect(aWindow.Size()), &aWindow);
sl@0
  1537
sl@0
  1538
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL--");
sl@0
  1539
	}
sl@0
  1540
sl@0
  1541
void CVideoPlayerUtility::CBody::DoAddDisplayWindowL(RWsSession& aWs, TInt aDisplayId, RWindowBase& aWindow,
sl@0
  1542
								const TRect& aClipRect, const TRect& aVideoExtent, RWindow* aWindow2)
sl@0
  1543
	{
sl@0
  1544
	iWs = &aWs;
sl@0
  1545
sl@0
  1546
	// check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
sl@0
  1547
	if (!iControllerOpen)
sl@0
  1548
		{
sl@0
  1549
		User::Leave(KErrNotReady);
sl@0
  1550
		}
sl@0
  1551
sl@0
  1552
	// make sure window isn't already added on another display
sl@0
  1553
	TRAPD(err, CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
sl@0
  1554
	if (err != KErrNotFound)
sl@0
  1555
		{
sl@0
  1556
		// If err is something else but KErrNone leave
sl@0
  1557
		User::LeaveIfError(err);
sl@0
  1558
		// Window is already in use
sl@0
  1559
		User::Leave(KErrInUse);
sl@0
  1560
		}
sl@0
  1561
sl@0
  1562
	TInt pos = iActiveDisplays.FindInOrder(aDisplayId, CMediaClientVideoDisplayBody::CompareByDisplay);
sl@0
  1563
	CMediaClientVideoDisplayBody* display = NULL;
sl@0
  1564
sl@0
  1565
	if (pos == KErrNotFound)
sl@0
  1566
		{
sl@0
  1567
		if(iSurfaceId.IsNull())
sl@0
  1568
			{
sl@0
  1569
			display = CMediaClientVideoDisplayBody::NewL(aDisplayId, ETrue);
sl@0
  1570
			}
sl@0
  1571
		else
sl@0
  1572
			{
sl@0
  1573
			display = CMediaClientVideoDisplayBody::NewL(aDisplayId, iSurfaceId, iSurfaceCropRect, iAspectRatio, ETrue);
sl@0
  1574
			}
sl@0
  1575
		CleanupStack::PushL(display);
sl@0
  1576
		iActiveDisplays.InsertInOrderL(display, CMediaClientVideoDisplayBody::Compare);
sl@0
  1577
		CleanupStack::Pop(display);
sl@0
  1578
		}
sl@0
  1579
	else 
sl@0
  1580
		{
sl@0
  1581
		User::LeaveIfError(pos);
sl@0
  1582
		display = iActiveDisplays[pos];
sl@0
  1583
		}
sl@0
  1584
sl@0
  1585
	display->AddDisplayWindowL(&aWindow, aClipRect, iCropRegion, aVideoExtent, iGlobalScaleWidth, iGlobalScaleHeight,
sl@0
  1586
								iGlobalRotation, iGlobalAutoScaleType, iGlobalHorizPos, iGlobalVertPos, aWindow2);
sl@0
  1587
sl@0
  1588
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1589
	if (iSubtitleUtility)
sl@0
  1590
		{
sl@0
  1591
		// subtitles were enabled already, so enable subtitles on this window
sl@0
  1592
		TMMFSubtitleWindowConfig config;
sl@0
  1593
		config.iWindowId = aWindow.WsHandle();
sl@0
  1594
		config.iWindowClipRect = aClipRect;
sl@0
  1595
		config.iDisplayMode = aWindow.DisplayMode();
sl@0
  1596
		config.iRotation = iGlobalRotation;
sl@0
  1597
		iSubtitleUtility->AddSubtitleConfig(config); // ignore error from add subtitle config because the window can still display video properly
sl@0
  1598
		}
sl@0
  1599
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1600
	}
sl@0
  1601
sl@0
  1602
void CVideoPlayerUtility::CBody::DoUpdateDisplayWindowL(RWsSession& aWs, RWindowBase& aWindow,
sl@0
  1603
                                const TRect& aClipRect, const TRect& aVideoExtent, RWindow* aWindow2)
sl@0
  1604
    {
sl@0
  1605
    iWs = &aWs;
sl@0
  1606
sl@0
  1607
    // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
sl@0
  1608
    if (!iControllerOpen)
sl@0
  1609
        {
sl@0
  1610
        User::Leave(KErrNotReady);
sl@0
  1611
        }
sl@0
  1612
sl@0
  1613
    CMediaClientVideoDisplayBody* display = NULL;
sl@0
  1614
    TRAPD(err, display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
sl@0
  1615
    User::LeaveIfError(err);
sl@0
  1616
sl@0
  1617
    display->UpdateDisplayWindowL(&aWindow, aClipRect, iCropRegion, aVideoExtent, iGlobalScaleWidth, iGlobalScaleHeight,
sl@0
  1618
                                iGlobalRotation, iGlobalAutoScaleType, iGlobalHorizPos, iGlobalVertPos, aWindow2);
sl@0
  1619
sl@0
  1620
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1621
    if (iSubtitleUtility)
sl@0
  1622
        {
sl@0
  1623
        // subtitles were enabled already, so update subtitles on this window
sl@0
  1624
        TMMFSubtitleWindowConfig config;
sl@0
  1625
        config.iWindowId = aWindow.WsHandle();
sl@0
  1626
        config.iWindowClipRect = aClipRect;
sl@0
  1627
        config.iDisplayMode = aWindow.DisplayMode();
sl@0
  1628
        config.iRotation = iGlobalRotation;
sl@0
  1629
        iSubtitleUtility->UpdateSubtitleConfig(config); // ignore error from add subtitle config because the window can still display video properly
sl@0
  1630
        }
sl@0
  1631
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1632
    }
sl@0
  1633
sl@0
  1634
void CVideoPlayerUtility::CBody::RemoveDisplayWindow(RWindowBase& aWindow)
sl@0
  1635
	{
sl@0
  1636
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplayWindow++");
sl@0
  1637
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveDisplayWindow - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
  1638
sl@0
  1639
    CMediaClientVideoDisplayBody* display = NULL;
sl@0
  1640
	TRAPD(err, display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
sl@0
  1641
	
sl@0
  1642
	if (err == KErrNone)
sl@0
  1643
		{		
sl@0
  1644
		display->RemoveDisplayWindow(aWindow);
sl@0
  1645
	
sl@0
  1646
		if (!display->IsUsed())
sl@0
  1647
sl@0
  1648
			{
sl@0
  1649
			TInt pos = iActiveDisplays.Find(display);
sl@0
  1650
			iActiveDisplays.Remove(pos);
sl@0
  1651
			delete display;
sl@0
  1652
			}
sl@0
  1653
sl@0
  1654
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1655
		if (iSubtitleUtility)
sl@0
  1656
			{
sl@0
  1657
			// subtitles are enabled, so remove window config, ignore error
sl@0
  1658
			iSubtitleUtility->RemoveSubtitleConfig(aWindow.WsHandle());
sl@0
  1659
			}
sl@0
  1660
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1661
		}	
sl@0
  1662
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplayWindow--");
sl@0
  1663
	}
sl@0
  1664
sl@0
  1665
void CVideoPlayerUtility::CBody::AddDisplayL(TInt aDisplay, MMMFSurfaceEventHandler& aEventHandler)
sl@0
  1666
	{
sl@0
  1667
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayL");
sl@0
  1668
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayL - aDisplay %d", aDisplay);
sl@0
  1669
	if (!iControllerOpen)
sl@0
  1670
		{
sl@0
  1671
		User::Leave(KErrNotReady);
sl@0
  1672
		}
sl@0
  1673
	
sl@0
  1674
	TInt err = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
sl@0
  1675
	
sl@0
  1676
	if (err == KErrNotFound)
sl@0
  1677
		{
sl@0
  1678
		CMediaClientVideoDisplayBody* display;
sl@0
  1679
		if(iSurfaceId.IsNull())
sl@0
  1680
			{
sl@0
  1681
			display = CMediaClientVideoDisplayBody::NewL(aDisplay, ETrue);
sl@0
  1682
			}
sl@0
  1683
		else
sl@0
  1684
			{
sl@0
  1685
			display = CMediaClientVideoDisplayBody::NewL(aDisplay, iSurfaceId, iSurfaceCropRect, iAspectRatio, ETrue);
sl@0
  1686
			}
sl@0
  1687
		CleanupStack::PushL(display);
sl@0
  1688
		iActiveDisplays.InsertInOrderL(display, CMediaClientVideoDisplayBody::Compare);
sl@0
  1689
		CleanupStack::Pop(display);
sl@0
  1690
		display->AddDisplayL(aEventHandler);
sl@0
  1691
		}
sl@0
  1692
	else
sl@0
  1693
		{
sl@0
  1694
		User::LeaveIfError(err);
sl@0
  1695
		iActiveDisplays[err]->AddDisplayL(aEventHandler);
sl@0
  1696
		}
sl@0
  1697
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayL--");
sl@0
  1698
	}
sl@0
  1699
sl@0
  1700
void CVideoPlayerUtility::CBody::RemoveDisplay(TInt aDisplay)
sl@0
  1701
	{
sl@0
  1702
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplay++");
sl@0
  1703
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveDisplay - aDisplay %d", aDisplay);
sl@0
  1704
	TInt pos = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
sl@0
  1705
	
sl@0
  1706
	if (pos >= KErrNone)
sl@0
  1707
		{
sl@0
  1708
		CMediaClientVideoDisplayBody* disp = iActiveDisplays[pos];
sl@0
  1709
		disp->RemoveDisplay();
sl@0
  1710
		
sl@0
  1711
		if (!disp->HasWindows())
sl@0
  1712
			{
sl@0
  1713
			iActiveDisplays.Remove(pos);
sl@0
  1714
			delete disp;
sl@0
  1715
			}
sl@0
  1716
		}
sl@0
  1717
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplay--");
sl@0
  1718
	}
sl@0
  1719
sl@0
  1720
void CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow(
sl@0
  1721
            const RWindowBase& aWindow,
sl@0
  1722
            const TRect& aFromWindowRect,
sl@0
  1723
            const TRect& aFromClipRect,
sl@0
  1724
            TRect& aToWindowRect,
sl@0
  1725
            TRect& aToClipRect)
sl@0
  1726
    {
sl@0
  1727
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow++");
sl@0
  1728
    TPoint windowOrigin = aWindow.AbsPosition();
sl@0
  1729
    
sl@0
  1730
    // window rect
sl@0
  1731
    aToWindowRect.iTl.iX = aFromWindowRect.iTl.iX - windowOrigin.iX;
sl@0
  1732
    aToWindowRect.iTl.iY = aFromWindowRect.iTl.iY - windowOrigin.iY;
sl@0
  1733
    aToWindowRect.iBr.iX = aFromWindowRect.iBr.iX - windowOrigin.iX;
sl@0
  1734
    aToWindowRect.iBr.iY = aFromWindowRect.iBr.iY - windowOrigin.iY;
sl@0
  1735
    
sl@0
  1736
    // clip rect
sl@0
  1737
    aToClipRect.iTl.iX = aFromClipRect.iTl.iX - windowOrigin.iX;
sl@0
  1738
    aToClipRect.iTl.iY = aFromClipRect.iTl.iY - windowOrigin.iY;
sl@0
  1739
    aToClipRect.iBr.iX = aFromClipRect.iBr.iX - windowOrigin.iX;
sl@0
  1740
    aToClipRect.iBr.iY = aFromClipRect.iBr.iY - windowOrigin.iY;
sl@0
  1741
sl@0
  1742
    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow - New Window rect %d,%d - %d,%d", aToWindowRect.iTl.iX, aToWindowRect.iTl.iY, aToWindowRect.iBr.iX, aToWindowRect.iBr.iY);
sl@0
  1743
    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow - New Clip rect %d,%d - %d,%d", aToClipRect.iTl.iX, aToClipRect.iTl.iY, aToClipRect.iBr.iX, aToClipRect.iBr.iY);
sl@0
  1744
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow--");
sl@0
  1745
    }
sl@0
  1746
sl@0
  1747
void CVideoPlayerUtility::CBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent)
sl@0
  1748
	{
sl@0
  1749
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetVideoExtentL++");
sl@0
  1750
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetVideoExtentL - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
  1751
    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetVideoExtentL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
sl@0
  1752
sl@0
  1753
    // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
sl@0
  1754
	if (!iControllerOpen)
sl@0
  1755
		{
sl@0
  1756
		User::Leave(KErrNotReady);
sl@0
  1757
		}
sl@0
  1758
		
sl@0
  1759
	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
sl@0
  1760
	display->SetVideoExtentL(aWindow, aVideoExtent, iCropRegion);
sl@0
  1761
sl@0
  1762
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetVideoExtentL--");
sl@0
  1763
	}
sl@0
  1764
sl@0
  1765
void CVideoPlayerUtility::CBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect)
sl@0
  1766
	{
sl@0
  1767
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetWindowClipRectL++");
sl@0
  1768
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetWindowClipRectL - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
  1769
    DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetWindowClipRectL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
sl@0
  1770
sl@0
  1771
    // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
sl@0
  1772
	if (!iControllerOpen)
sl@0
  1773
		{
sl@0
  1774
		User::Leave(KErrNotReady);
sl@0
  1775
		}
sl@0
  1776
sl@0
  1777
	TRect winRect(aWindow.Size());
sl@0
  1778
sl@0
  1779
	if (!RectContains(winRect, aWindowClipRect))
sl@0
  1780
		{
sl@0
  1781
		User::Leave(KErrArgument);
sl@0
  1782
		}
sl@0
  1783
		
sl@0
  1784
	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
sl@0
  1785
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1786
	RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
sl@0
  1787
	TInt pos = windows.Find(aWindow.WsHandle(), CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
sl@0
  1788
	User::LeaveIfError(pos);
sl@0
  1789
	
sl@0
  1790
	CMediaClientVideoDisplayBody::TWindowData& currentWin = windows[pos];
sl@0
  1791
	if (currentWin.iClipRect != aWindowClipRect)
sl@0
  1792
		{
sl@0
  1793
		// update config only if setting has actually changed
sl@0
  1794
		display->SetWindowClipRectL(aWindow, aWindowClipRect, iCropRegion);
sl@0
  1795
sl@0
  1796
		if (iSubtitleUtility)
sl@0
  1797
			{
sl@0
  1798
			TMMFSubtitleWindowConfig config;
sl@0
  1799
			GetSubtitleConfigFromWindowData(currentWin, config);
sl@0
  1800
sl@0
  1801
			iSubtitleUtility->UpdateSubtitleConfig(config);
sl@0
  1802
			}
sl@0
  1803
		}
sl@0
  1804
#else
sl@0
  1805
	display->SetWindowClipRectL(aWindow, aWindowClipRect, iCropRegion);
sl@0
  1806
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1807
sl@0
  1808
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetWindowClipRectL--");
sl@0
  1809
	}
sl@0
  1810
sl@0
  1811
// Check if the controller supports the graphics surface. Has to be called after resource opened.
sl@0
  1812
TInt CVideoPlayerUtility::CBody::CheckSurfaceSupported()
sl@0
  1813
	{
sl@0
  1814
	TInt err = iFindAndOpenController->SurfaceSupported();
sl@0
  1815
		
sl@0
  1816
	if (err == KErrNone)
sl@0
  1817
		{
sl@0
  1818
		iGraphicsSurfaceSupported = ETrue;
sl@0
  1819
		}
sl@0
  1820
	else 
sl@0
  1821
		{
sl@0
  1822
		iGraphicsSurfaceSupported = EFalse;
sl@0
  1823
		}
sl@0
  1824
		
sl@0
  1825
	return err;
sl@0
  1826
	}
sl@0
  1827
sl@0
  1828
TBool CVideoPlayerUtility::CBody::RectContains(const TRect& aLeft, const TRect& aRight)
sl@0
  1829
	{
sl@0
  1830
	return !(aLeft.iTl.iX > aRight.iTl.iX || 
sl@0
  1831
			aLeft.iTl.iY > aRight.iTl.iY ||
sl@0
  1832
	    	aLeft.iBr.iX < aRight.iBr.iX || 
sl@0
  1833
	    	aLeft.iBr.iY < aRight.iBr.iY);
sl@0
  1834
	}
sl@0
  1835
	
sl@0
  1836
	
sl@0
  1837
void CVideoPlayerUtility::CBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType)
sl@0
  1838
	{
sl@0
  1839
	SetAutoScaleL(aWindow, aScaleType, EHorizontalAlignCenter, EVerticalAlignCenter);
sl@0
  1840
	}
sl@0
  1841
	
sl@0
  1842
void CVideoPlayerUtility::CBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
sl@0
  1843
	{
sl@0
  1844
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL++");
sl@0
  1845
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
  1846
    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetAutoScaleL - aScaleType %d, aHorizPos %d, aVertPos %d", aScaleType, aHorizPos, aVertPos);
sl@0
  1847
sl@0
  1848
    if (!iControllerOpen)
sl@0
  1849
		{
sl@0
  1850
		User::Leave(KErrNotReady);
sl@0
  1851
		}
sl@0
  1852
		
sl@0
  1853
	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
sl@0
  1854
	display->SetAutoScaleL(aWindow, aScaleType, aHorizPos, aVertPos, iCropRegion);
sl@0
  1855
sl@0
  1856
	DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL--");
sl@0
  1857
	}
sl@0
  1858
sl@0
  1859
void CVideoPlayerUtility::CBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation)
sl@0
  1860
	{
sl@0
  1861
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL++");
sl@0
  1862
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
  1863
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aRotation %d", aRotation);
sl@0
  1864
sl@0
  1865
    if (!iControllerOpen)
sl@0
  1866
		{
sl@0
  1867
		User::Leave(KErrNotReady);
sl@0
  1868
		}
sl@0
  1869
sl@0
  1870
	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
sl@0
  1871
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1872
	RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
sl@0
  1873
	TInt pos = windows.Find(aWindow.WsHandle(), CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
sl@0
  1874
	User::LeaveIfError(pos);
sl@0
  1875
	
sl@0
  1876
	CMediaClientVideoDisplayBody::TWindowData& currentWin = windows[pos];
sl@0
  1877
	if (currentWin.iRotation != aRotation)
sl@0
  1878
		{
sl@0
  1879
		display->SetRotationL(aWindow, aRotation, iCropRegion);
sl@0
  1880
sl@0
  1881
		if (iSubtitleUtility)
sl@0
  1882
			{
sl@0
  1883
			TMMFSubtitleWindowConfig config;
sl@0
  1884
			GetSubtitleConfigFromWindowData(currentWin, config);
sl@0
  1885
sl@0
  1886
			iSubtitleUtility->UpdateSubtitleConfig(config);
sl@0
  1887
			}
sl@0
  1888
		}
sl@0
  1889
#else
sl@0
  1890
	display->SetRotationL(aWindow, aRotation, iCropRegion);
sl@0
  1891
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  1892
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL--");
sl@0
  1893
	}
sl@0
  1894
	
sl@0
  1895
TVideoRotation CVideoPlayerUtility::CBody::RotationL(const RWindowBase& aWindow) const
sl@0
  1896
	{
sl@0
  1897
	if (!iControllerOpen)
sl@0
  1898
		{
sl@0
  1899
		User::Leave(KErrNotReady);
sl@0
  1900
		}
sl@0
  1901
	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
sl@0
  1902
	return display->RotationL(aWindow);
sl@0
  1903
	}
sl@0
  1904
	
sl@0
  1905
void CVideoPlayerUtility::CBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage)
sl@0
  1906
	{
sl@0
  1907
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL++");
sl@0
  1908
    DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetScaleFactorL - aWindow WsHandle 0x%X", aWindow.WsHandle());
sl@0
  1909
    DEBUG_PRINTF3("CVideoPlayerUtility::CBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
sl@0
  1910
	if (!iControllerOpen)
sl@0
  1911
		{
sl@0
  1912
		User::Leave(KErrNotReady);
sl@0
  1913
		
sl@0
  1914
		}
sl@0
  1915
	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
sl@0
  1916
	display->SetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage, iCropRegion);
sl@0
  1917
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL--");
sl@0
  1918
	}
sl@0
  1919
	
sl@0
  1920
void CVideoPlayerUtility::CBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage) const
sl@0
  1921
	{
sl@0
  1922
	if (!iControllerOpen)
sl@0
  1923
		{
sl@0
  1924
		User::Leave(KErrNotReady);
sl@0
  1925
		
sl@0
  1926
		}
sl@0
  1927
	CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
sl@0
  1928
	display->GetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage);
sl@0
  1929
	}
sl@0
  1930
sl@0
  1931
void CVideoPlayerUtility::CBody::SetExternalDisplaySwitchingL(TInt aDisplay, TBool aControl)
sl@0
  1932
    {
sl@0
  1933
    TInt pos = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
sl@0
  1934
    
sl@0
  1935
    User::LeaveIfError(pos);
sl@0
  1936
    
sl@0
  1937
    iActiveDisplays[pos]->SetExternalDisplaySwitchingL(aControl);
sl@0
  1938
    }
sl@0
  1939
sl@0
  1940
#endif // SYMBIAN_BUILD_GCE
sl@0
  1941
sl@0
  1942
void CVideoPlayerUtility::CBody::SetPlayVelocityL(TInt aVelocity)
sl@0
  1943
	{
sl@0
  1944
	// Leave if Open is not yet called on controller.
sl@0
  1945
	if(!iEventOpenReceived)
sl@0
  1946
		{
sl@0
  1947
		User::Leave(KErrNotReady);
sl@0
  1948
		}
sl@0
  1949
	
sl@0
  1950
	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetPlayVelocity(aVelocity));	
sl@0
  1951
	}
sl@0
  1952
sl@0
  1953
const TInt KDefaultPlayVelocity = 100;
sl@0
  1954
sl@0
  1955
TInt CVideoPlayerUtility::CBody::PlayVelocityL() const
sl@0
  1956
	{
sl@0
  1957
	TInt velocity;
sl@0
  1958
	TInt error;
sl@0
  1959
sl@0
  1960
	// Leave if Open is not yet called.
sl@0
  1961
	if( !iEventOpenReceived )
sl@0
  1962
		{
sl@0
  1963
		User::Leave(KErrNotReady);
sl@0
  1964
		}
sl@0
  1965
	
sl@0
  1966
	error = iVideoPlayControllerExtCustomCommands.PlayVelocity(velocity);
sl@0
  1967
	/* if customcommand is not implemented by controller pluggin return default value(100) */
sl@0
  1968
	if (KErrNotSupported == error)
sl@0
  1969
		{
sl@0
  1970
		velocity = KDefaultPlayVelocity;
sl@0
  1971
		}
sl@0
  1972
	else
sl@0
  1973
		{
sl@0
  1974
		User::LeaveIfError(	error );	
sl@0
  1975
		}
sl@0
  1976
	return velocity;
sl@0
  1977
	}
sl@0
  1978
void CVideoPlayerUtility::CBody::StepFrameL(TInt aStep)
sl@0
  1979
	{
sl@0
  1980
	//Leave if not in paused state. This functionality is supported only in paused state.
sl@0
  1981
	if( (!iEventOpenReceived ) || ( EPaused != iState ) )
sl@0
  1982
		{
sl@0
  1983
		User::Leave(KErrNotReady);
sl@0
  1984
		}
sl@0
  1985
sl@0
  1986
	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.StepFrame(aStep));
sl@0
  1987
	}
sl@0
  1988
void CVideoPlayerUtility::CBody::GetPlayRateCapabilitiesL(TVideoPlayRateCapabilities& aCapabilities) const
sl@0
  1989
	{
sl@0
  1990
	TInt error;
sl@0
  1991
sl@0
  1992
	// Leave if Open is not yet called on controller.
sl@0
  1993
	if( !iEventOpenReceived )
sl@0
  1994
		{
sl@0
  1995
		User::Leave(KErrNotReady);
sl@0
  1996
		}
sl@0
  1997
	
sl@0
  1998
	error = iVideoPlayControllerExtCustomCommands.GetPlayRateCapabilities(aCapabilities);
sl@0
  1999
	/* if customcommand is not implemented by controller pluggin return not supported */
sl@0
  2000
	if (KErrNotSupported == error)
sl@0
  2001
		{
sl@0
  2002
		aCapabilities.iPlayBackward = EFalse;
sl@0
  2003
		aCapabilities.iPlayForward = EFalse;
sl@0
  2004
		aCapabilities.iStepBackward = EFalse;
sl@0
  2005
		aCapabilities.iStepForward = EFalse;
sl@0
  2006
		}
sl@0
  2007
	else
sl@0
  2008
		{
sl@0
  2009
		User::LeaveIfError(error);
sl@0
  2010
		}	
sl@0
  2011
	}
sl@0
  2012
void CVideoPlayerUtility::CBody::SetVideoEnabledL(TBool aVideoEnabled)
sl@0
  2013
	{
sl@0
  2014
	// Leave if Open is not yet called or not in stopped state.
sl@0
  2015
	if( (!iEventOpenReceived ) || ( EStopped != iState ) )
sl@0
  2016
		{
sl@0
  2017
		User::Leave(KErrNotReady);
sl@0
  2018
		}
sl@0
  2019
	
sl@0
  2020
	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetVideoEnabled(aVideoEnabled));
sl@0
  2021
	}
sl@0
  2022
TBool CVideoPlayerUtility::CBody::VideoEnabledL() const
sl@0
  2023
	{
sl@0
  2024
	TBool videoEnabled;
sl@0
  2025
	TInt error;
sl@0
  2026
sl@0
  2027
	// Leave if Open is not yet called.
sl@0
  2028
	if( !iEventOpenReceived )
sl@0
  2029
		{
sl@0
  2030
		User::Leave(KErrNotReady);
sl@0
  2031
		}
sl@0
  2032
	
sl@0
  2033
	error = iVideoPlayControllerExtCustomCommands.VideoEnabled(videoEnabled);
sl@0
  2034
	/* if customcommand is not implemented by controller pluggin return default value ETrue */
sl@0
  2035
	if (KErrNotSupported == error)
sl@0
  2036
		{
sl@0
  2037
		videoEnabled = ETrue;
sl@0
  2038
		}
sl@0
  2039
	else
sl@0
  2040
		{
sl@0
  2041
		User::LeaveIfError(error);
sl@0
  2042
		}	
sl@0
  2043
	return videoEnabled;
sl@0
  2044
	}
sl@0
  2045
void CVideoPlayerUtility::CBody::SetAudioEnabledL(TBool aAudioEnabled)
sl@0
  2046
	{
sl@0
  2047
	// Leave if Open is not yet called or not in stopped state.
sl@0
  2048
	if( (!iEventOpenReceived ) || ( EStopped != iState ) )
sl@0
  2049
		{
sl@0
  2050
		User::Leave(KErrNotReady);
sl@0
  2051
		}
sl@0
  2052
	
sl@0
  2053
	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAudioEnabled(aAudioEnabled));
sl@0
  2054
	}
sl@0
  2055
void CVideoPlayerUtility::CBody::SetAutoScaleL(TAutoScaleType aScaleType)
sl@0
  2056
	{
sl@0
  2057
	SetAutoScaleL(aScaleType, EHorizontalAlignCenter, EVerticalAlignCenter);
sl@0
  2058
	}
sl@0
  2059
void CVideoPlayerUtility::CBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
sl@0
  2060
	{
sl@0
  2061
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL++");
sl@0
  2062
    DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetAutoScaleL - aScaleType %d, aHorizPos %d, aVertPos %d", aScaleType, aHorizPos, aVertPos);
sl@0
  2063
sl@0
  2064
    // Leave if Open is not yet called.
sl@0
  2065
	if(!iEventOpenReceived )
sl@0
  2066
		{
sl@0
  2067
		User::Leave(KErrNotReady);
sl@0
  2068
		}	
sl@0
  2069
sl@0
  2070
#ifdef SYMBIAN_BUILD_GCE
sl@0
  2071
	if (!iGraphicsSurfaceSupported)
sl@0
  2072
		{
sl@0
  2073
		User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAutoScale(aScaleType, aHorizPos, aVertPos));
sl@0
  2074
		}
sl@0
  2075
	else
sl@0
  2076
		{
sl@0
  2077
		// Auto scale setting is not sent to controller when graphics surfaces are used.
sl@0
  2078
		// If the surface has been created, perform auto scale with the help of graphics surfaces;
sl@0
  2079
		// otherwise, just store the auto scale info.
sl@0
  2080
		iGlobalAutoScaleType = aScaleType;
sl@0
  2081
		iGlobalHorizPos = aHorizPos;
sl@0
  2082
		iGlobalVertPos = aVertPos;
sl@0
  2083
		
sl@0
  2084
		TInt count = iActiveDisplays.Count();
sl@0
  2085
		
sl@0
  2086
		for (TInt i = 0; i < count; ++i)
sl@0
  2087
			{
sl@0
  2088
			iActiveDisplays[i]->SetAutoScaleL(aScaleType, aHorizPos, aVertPos, iCropRegion);
sl@0
  2089
			}
sl@0
  2090
		}
sl@0
  2091
#else
sl@0
  2092
	User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAutoScale(aScaleType, aHorizPos, aVertPos));
sl@0
  2093
#endif // SYMBIAN_BUILD_GCE
sl@0
  2094
    DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL--");
sl@0
  2095
	}
sl@0
  2096
sl@0
  2097
#ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  2098
TBool CVideoPlayerUtility::CBody::SubtitlesAvailable()
sl@0
  2099
	{
sl@0
  2100
	if (!iControllerOpen)
sl@0
  2101
		{
sl@0
  2102
		return EFalse;
sl@0
  2103
		}
sl@0
  2104
sl@0
  2105
	return CMMFSubtitleUtility::SubtitlesAvailable(iController);
sl@0
  2106
	}
sl@0
  2107
sl@0
  2108
void CVideoPlayerUtility::CBody::EnableSubtitlesL()
sl@0
  2109
	{
sl@0
  2110
	// Check if video file and controller is opened
sl@0
  2111
	__ASSERT_ALWAYS(iControllerOpen, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilityFileNotOpened, KErrNotReady));
sl@0
  2112
	// Check if subtitles are already enabled
sl@0
  2113
	__ASSERT_ALWAYS(!iSubtitleUtility, User::Leave(KErrInUse));
sl@0
  2114
	// Check if display window is added
sl@0
  2115
	TBool windowsAdded = EFalse;
sl@0
  2116
	for (TInt i = iActiveDisplays.Count()-1; (i >= 0 && windowsAdded == EFalse); --i)
sl@0
  2117
		{
sl@0
  2118
		CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
sl@0
  2119
		windowsAdded = display->HasWindows();
sl@0
  2120
		}
sl@0
  2121
	__ASSERT_ALWAYS(windowsAdded, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilityNoWindowAdded, KErrNotReady));
sl@0
  2122
sl@0
  2123
sl@0
  2124
	iSubtitleUtility = CMMFSubtitleUtility::NewL(iController, *iWs);
sl@0
  2125
	TInt err = iSubtitleUtility->EnableSubtitles();
sl@0
  2126
	if (KErrNone != err)
sl@0
  2127
		{
sl@0
  2128
		delete iSubtitleUtility;
sl@0
  2129
		iSubtitleUtility = NULL;
sl@0
  2130
		if (KErrNotSupported == err || KErrNotFound == err)
sl@0
  2131
			{
sl@0
  2132
			// controller does not support subtitles or subtitle source not found,
sl@0
  2133
			// panic client because they should have called SubtitlesAvailable first
sl@0
  2134
			VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotSupported, err);
sl@0
  2135
			}
sl@0
  2136
		
sl@0
  2137
		// leave in release mode or any other error
sl@0
  2138
		User::Leave(err);
sl@0
  2139
		}
sl@0
  2140
sl@0
  2141
	TBool subtitleEnabled = EFalse;
sl@0
  2142
	TInt count = iActiveDisplays.Count();
sl@0
  2143
	
sl@0
  2144
	// add the windows in the orders that they were added
sl@0
  2145
	for (TInt i = 0; i < count; ++i)
sl@0
  2146
		{
sl@0
  2147
		CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
sl@0
  2148
		err = EnableSubtitles(*display);
sl@0
  2149
		
sl@0
  2150
		if (KErrNone == err)
sl@0
  2151
			{
sl@0
  2152
			subtitleEnabled = ETrue;
sl@0
  2153
			}
sl@0
  2154
		}
sl@0
  2155
sl@0
  2156
	// no subtitle window was enabled successfully, enable subtitle failed
sl@0
  2157
	if (!subtitleEnabled)
sl@0
  2158
		{
sl@0
  2159
		DisableSubtitles();	// disable subtitle on controller side
sl@0
  2160
		User::Leave(err); // Leave with error returned by last EnableSubtitles call
sl@0
  2161
		}
sl@0
  2162
	}
sl@0
  2163
sl@0
  2164
void CVideoPlayerUtility::CBody::DisableSubtitles()
sl@0
  2165
	{
sl@0
  2166
	if (iSubtitleUtility)
sl@0
  2167
		{
sl@0
  2168
		iSubtitleUtility->DisableSubtitles();
sl@0
  2169
		
sl@0
  2170
		delete iSubtitleUtility;
sl@0
  2171
		iSubtitleUtility = NULL;
sl@0
  2172
		}
sl@0
  2173
	}
sl@0
  2174
sl@0
  2175
TArray<TLanguage> CVideoPlayerUtility::CBody::SupportedSubtitleLanguagesL()
sl@0
  2176
	{
sl@0
  2177
	// Check if subtitles have been enabled
sl@0
  2178
	__ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
sl@0
  2179
sl@0
  2180
	return iSubtitleUtility->SupportedSubtitleLanguagesL();
sl@0
  2181
	}
sl@0
  2182
sl@0
  2183
TLanguage CVideoPlayerUtility::CBody::SubtitleLanguageL()
sl@0
  2184
	{
sl@0
  2185
	// Check if subtitles have been enabled
sl@0
  2186
	__ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
sl@0
  2187
sl@0
  2188
	return iSubtitleUtility->SubtitleLanguage();
sl@0
  2189
	}
sl@0
  2190
sl@0
  2191
void CVideoPlayerUtility::CBody::SetSubtitleLanguageL(TLanguage aLanguage)
sl@0
  2192
	{
sl@0
  2193
	// Check if subtitles have been enabled
sl@0
  2194
	__ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
sl@0
  2195
sl@0
  2196
	TInt err = iSubtitleUtility->SetSubtitleLanguage(aLanguage);
sl@0
  2197
	if (KErrNotSupported == err)
sl@0
  2198
		{
sl@0
  2199
		// panic on debug because client should call SupportedSubtitleLanguagesL() first
sl@0
  2200
		VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleLanguageNotSupported, KErrNotSupported);
sl@0
  2201
		}
sl@0
  2202
	User::LeaveIfError(err);
sl@0
  2203
	}
sl@0
  2204
sl@0
  2205
void CVideoPlayerUtility::CBody::RedrawSubtitle(RWindow& aWindow, const TRect &aRect)
sl@0
  2206
	{
sl@0
  2207
	if (iSubtitleUtility)
sl@0
  2208
		{
sl@0
  2209
		// subtitle is enabled
sl@0
  2210
		RWindow* window = FindWindowWithWsHandle(iActiveDisplays, aWindow.WsHandle());
sl@0
  2211
		if (window) // check that window was added for video playback
sl@0
  2212
			{
sl@0
  2213
			iSubtitleUtility->RedrawSubtitle(aWindow, aRect);
sl@0
  2214
			}
sl@0
  2215
		}
sl@0
  2216
	// else ignore the redraw request
sl@0
  2217
	}
sl@0
  2218
sl@0
  2219
RWindow* CVideoPlayerUtility::CBody::FindWindowWithWsHandle(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, TInt aWsHandle)
sl@0
  2220
	{
sl@0
  2221
	TInt count = aDisplays.Count();
sl@0
  2222
	
sl@0
  2223
	for (TInt i = 0; i < count; ++i)
sl@0
  2224
		{
sl@0
  2225
		CMediaClientVideoDisplayBody* display = aDisplays[i];
sl@0
  2226
		RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
sl@0
  2227
		TInt pos = windows.Find(aWsHandle, CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
sl@0
  2228
		if (pos >= 0)
sl@0
  2229
			{
sl@0
  2230
			return windows[pos].iWindow2;
sl@0
  2231
			}
sl@0
  2232
		}
sl@0
  2233
		
sl@0
  2234
	return NULL;
sl@0
  2235
	}
sl@0
  2236
sl@0
  2237
void CVideoPlayerUtility::CBody::GetSubtitleConfigFromWindowData(CMediaClientVideoDisplayBody::TWindowData& aWindowData, TMMFSubtitleWindowConfig& aConfig)
sl@0
  2238
	{
sl@0
  2239
	aConfig.iWindowId = aWindowData.iWindow->WsHandle();
sl@0
  2240
	aConfig.iWindowClipRect = aWindowData.iClipRect;
sl@0
  2241
	aConfig.iDisplayMode = aWindowData.iWindow->DisplayMode();
sl@0
  2242
	aConfig.iRotation = aWindowData.iRotation;
sl@0
  2243
	
sl@0
  2244
	}
sl@0
  2245
TInt CVideoPlayerUtility::CBody::EnableSubtitles(CMediaClientVideoDisplayBody& aDisplay)
sl@0
  2246
	{
sl@0
  2247
	TBool windowAdded = EFalse;
sl@0
  2248
	RArray<CMediaClientVideoDisplayBody::TWindowData> windows = aDisplay.Windows();
sl@0
  2249
	
sl@0
  2250
 	TInt count = windows.Count();
sl@0
  2251
	TInt err = KErrNone;	
sl@0
  2252
	// add the windows in the orders that they are added
sl@0
  2253
	for (TInt i = 0; i < count; ++i)
sl@0
  2254
		{
sl@0
  2255
		err = AddSubtitleConfig(windows[i]);
sl@0
  2256
		if (KErrNone == err)
sl@0
  2257
			{
sl@0
  2258
			windowAdded = ETrue;
sl@0
  2259
			}
sl@0
  2260
		}
sl@0
  2261
sl@0
  2262
	// Return the error code returned by the last AddSubtitleConfig call.
sl@0
  2263
	if (!windowAdded)
sl@0
  2264
		{
sl@0
  2265
		return err;
sl@0
  2266
		}
sl@0
  2267
	
sl@0
  2268
	return KErrNone;
sl@0
  2269
	}
sl@0
  2270
sl@0
  2271
TInt CVideoPlayerUtility::CBody::AddSubtitleConfig(CMediaClientVideoDisplayBody::TWindowData& aWindowData)
sl@0
  2272
	{
sl@0
  2273
	ASSERT(iSubtitleUtility);
sl@0
  2274
	TMMFSubtitleWindowConfig config;
sl@0
  2275
	GetSubtitleConfigFromWindowData(aWindowData, config);
sl@0
  2276
	
sl@0
  2277
	return iSubtitleUtility->AddSubtitleConfig(config);
sl@0
  2278
	}
sl@0
  2279
#endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
sl@0
  2280