First public contribution.
1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <mmf/common/mmfstandardcustomcommands.h>
18 #include <mmf/common/mmfdrmcustomcommands.h>
19 #include <mmf/common/mmfvideo.h>
20 #include <mmf/server/mmfdes.h>
21 #include <mmf/server/mmffile.h>
22 #include "mmfvideocallback.h"
23 #include "VideoPlayerBody.h"
24 #include "mmfclientvideocommon.h"
25 #include "mmfclientutility.h"
26 #include "mediaclientvideotrace.h"
28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
29 #include <mmf/common/mmfvideoenums.h>
32 #ifdef SYMBIAN_BUILD_GCE
33 #include <videoplayer2.h>
34 #include <surfaceeventhandler.h>
37 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
38 #include <mmf/common/mmfpaniccodes.h>
39 #include "mmfsubtitleutility.h"
40 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
42 using namespace ContentAccess;
44 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
47 void VPUDebugPanicOrLeaveL(TInt aVPUPanicCode, TInt aLeaveCode)
49 _LIT(KMMFVideoPlayerUtilityPanicCategory, "MMFVideoPlayUtil");
50 User::Panic(KMMFVideoPlayerUtilityPanicCategory, aVPUPanicCode);
51 User::Leave(aLeaveCode); // added for leavescan
55 void VPUDebugPanicOrLeaveL(TInt /*aVPUPanicCode*/, TInt aLeaveCode)
57 User::Leave(aLeaveCode);
61 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
63 CVideoPlayerUtility::CBody* CVideoPlayerUtility::CBody::NewL(CVideoPlayerUtility* aParent,
64 MVideoPlayerUtilityObserver& aObserver,
68 CWsScreenDevice& aScreenDevice,
70 const TRect& aScreenRect,
71 const TRect& aClipRect)
73 DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU1)++");
74 CBody* self = new(ELeave) CBody(aParent, aObserver, aScreenDevice.GetScreenNumber(), aPriority, aPref);
75 CleanupStack::PushL(self);
76 self->ConstructL(aWs, aScreenDevice, aWindow, aScreenRect, aClipRect);
78 DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU1)--");
82 #ifdef SYMBIAN_BUILD_GCE
83 CVideoPlayerUtility::CBody* CVideoPlayerUtility::CBody::NewL(CVideoPlayerUtility2* aParent,
84 MVideoPlayerUtilityObserver& aObserver,
88 DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU2)++");
89 CBody* self = new(ELeave) CBody(aParent, aObserver, aPriority, aPref);
90 CleanupStack::PushL(self);
93 DEBUG_PRINTF("CVideoPlayerUtility::CBody::NewL (CVPU2)--");
96 #endif // SYMBIAN_BUILD_GCE
98 CVideoPlayerUtility::CBody::~CBody()
100 DEBUG_PRINTF("CVideoPlayerUtility::CBody::~CBody++");
103 delete iControllerImplementationInformation;
104 delete iDirectScreenAccess;
105 delete iFindAndOpenController;
106 delete iControllerEventMonitor;
107 delete iFrameCallback;
108 delete iAsyncCallback;
111 if (iFbsSessionConnected)
112 iFbsSession.Disconnect();
113 DEBUG_PRINTF("CVideoPlayerUtility::CBody::~CBody--");
116 void CVideoPlayerUtility::CBody::Close()
118 DEBUG_PRINTF("CVideoPlayerUtility::CBody::Close++");
119 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
121 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
124 iAsyncCallback->Cancel();
126 iFrameCallback->Cancel();
127 if (iFindAndOpenController)
128 iFindAndOpenController->Close();
129 if (iControllerEventMonitor)
130 iControllerEventMonitor->Cancel();
131 if(iControllerImplementationInformation)
133 delete iControllerImplementationInformation;
134 iControllerImplementationInformation = NULL;
137 #ifdef SYMBIAN_BUILD_GCE
138 iActiveDisplays.ResetAndDestroy();
139 iSurfaceId = TSurfaceId::CreateNullId();
143 iControllerUid = KNullUid;
144 iControllerOpen = EFalse;
145 iDirectScreenAccessAbort = EFalse;
146 DEBUG_PRINTF("CVideoPlayerUtility::CBody::Close--");
149 CVideoPlayerUtility::CBody::CBody(CVideoPlayerUtility* aParent,
150 MVideoPlayerUtilityObserver& aObserver,
154 iVideoControllerCustomCommands(iController),
155 iVideoPlayControllerCustomCommands(iController),
156 iAudioPlayDeviceCustomCommands(iController),
157 iAudioRecordDeviceCustomCommands(iController),
158 iVideoDRMExtCustomCommands(iController),
159 iDRMCustomCommands(iController),
160 iVideoPlayControllerExtCustomCommands(iController),
161 iNotificationRegistrationCommands(iController),
162 #ifdef SYMBIAN_BUILD_GCE
163 iVideoPlaySurfaceSupportCustomCommands(iController),
165 iArnEventHolder(KNullUid),
166 iVideoSetInitScreenCustomCommands(iController),
167 iObserver(aObserver),
170 iScreenNumber(aScreenNumber)
171 #ifdef SYMBIAN_BUILD_GCE
172 ,iGlobalScaleWidth(100.0f),
173 iGlobalScaleHeight(100.0f),
174 iGlobalAutoScaleType(EAutoScaleBestFit), // Really need some platform specific way of defining this. Not everyone will want it.
175 iGlobalHorizPos(EHorizontalAlignCenter),
176 iGlobalVertPos(EVerticalAlignCenter)
179 iPrioritySettings.iPriority = aPriority;
180 iPrioritySettings.iPref = aPref;
183 #ifdef SYMBIAN_BUILD_GCE
184 CVideoPlayerUtility::CBody::CBody(CVideoPlayerUtility2* aParent,
185 MVideoPlayerUtilityObserver& aObserver,
188 iVideoControllerCustomCommands(iController),
189 iVideoPlayControllerCustomCommands(iController),
190 iAudioPlayDeviceCustomCommands(iController),
191 iAudioRecordDeviceCustomCommands(iController),
192 iVideoDRMExtCustomCommands(iController),
193 iDRMCustomCommands(iController),
194 iVideoPlayControllerExtCustomCommands(iController),
195 iNotificationRegistrationCommands(iController),
196 iVideoPlaySurfaceSupportCustomCommands(iController),
197 iArnEventHolder(KNullUid),
198 iVideoSetInitScreenCustomCommands(iController),
199 iObserver(aObserver),
203 iGlobalScaleWidth(100.0f),
204 iGlobalScaleHeight(100.0f),
205 iGlobalHorizPos(EHorizontalAlignCenter),
206 iGlobalVertPos(EVerticalAlignCenter)
208 iPrioritySettings.iPriority = aPriority;
209 iPrioritySettings.iPref = aPref;
212 void CVideoPlayerUtility::CBody::ConstructL()
214 DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL1++");
216 iFindAndOpenController = CMMFFindAndOpenController::NewL(*this);
217 iFindAndOpenController->SetSurfaceMode(iUsingVPU2, &iVideoPlaySurfaceSupportCustomCommands);
218 iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
219 iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EPlayback);
220 DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL1--");
223 #endif // SYMBIAN_BUILD_GCE
225 void CVideoPlayerUtility::CBody::ConstructL(RWsSession& aWs,
226 CWsScreenDevice& aScreenDevice,
227 RWindowBase& aWindow,
228 const TRect& aWindowRect,
229 const TRect& aClipRect)
231 DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL2++");
234 SetDisplayWindowL(aWs, aScreenDevice, aWindow, aWindowRect, aClipRect);
235 iFindAndOpenController = CMMFFindAndOpenController::NewL(*this);
236 #ifdef SYMBIAN_BUILD_GCE
237 iFindAndOpenController->SetSurfaceMode(iUsingVPU2, &iVideoPlaySurfaceSupportCustomCommands);
239 // If we open a controller with surface support we may render to surfaces. We need to store these
240 // so we can add the display as a surface rendering target.
243 iDisplayId = aScreenDevice.GetScreenNumber();
245 iWindowRect = aWindowRect;
246 iClipRect = aClipRect;
249 iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
250 iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, CMMFFindAndOpenController::EPlayback);
251 DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConstructL2--");
254 void CVideoPlayerUtility::CBody::CommonConstructL()
256 iControllerEventMonitor = CMMFControllerEventMonitor::NewL(*this, iController);
257 iMimeType = HBufC8::NewL(KMaxMimeTypeLength);
258 iAsyncCallback = new (ELeave) CMMFVideoPlayerCallback(iObserver);
259 iFrameCallback = new (ELeave) CMMFVideoPlayerCallback(iObserver);
260 User::LeaveIfError(iFbsSession.Connect());
261 iFbsSessionConnected = ETrue;
264 void CVideoPlayerUtility::CBody::Reset()
266 DEBUG_PRINTF("CVideoPlayerUtility::CBody::Reset++");
269 // reset all state variables
270 iEventOpenReceived = EFalse;
271 iCallbackOpenReceived = EFalse;
272 iOpenError = KErrNone;
273 #ifdef SYMBIAN_BUILD_GCE
274 iGraphicsSurfaceSupported = EFalse;
276 iControllerUid = KNullUid;
277 DEBUG_PRINTF("CVideoPlayerUtility::CBody::Reset--");
280 void CVideoPlayerUtility::CBody::SetAndUpdateWindow()
282 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAndUpdateWindow++");
283 if (iOpenError == KErrNone)
285 // Set the display window and update display region if the controller doesn't support graphics surface.
286 iOpenError = iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect, iClipRect);
289 if (iOpenError == KErrNone && iDirectScreenAccess && iDirectScreenAccess->DrawingRegion())
291 iOpenError = iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion());
293 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAndUpdateWindow--");
296 void CVideoPlayerUtility::CBody::MfaocComplete(
298 RMMFController* /*aController*/,
300 TMMFMessageDestination* /*aSourceHandle*/,
301 TMMFMessageDestination* /*aSinkHandle*/)
303 DEBUG_PRINTF("CVideoPlayerUtility::CBody::MfaocComplete++");
304 DEBUG_PRINTF3("CVideoPlayerUtility::CBody::MfaocComplete - aError %d, aControllerUid 0x%X", aError, aControllerUid.iUid);
305 iCallbackOpenReceived = ETrue;
307 // save the error in iOpenError -
308 // unless HandleEvent(KMMFEventCategoryVideoOpenComplete)
309 // has reported an error already
310 if (iOpenError == KErrNone)
313 if (iOpenError == KErrNone)
315 #ifdef SYMBIAN_BUILD_GCE
316 // Check if the graphics surfaces is supported
317 TInt err = CheckSurfaceSupported();
319 DEBUG_PRINTF4("CVideoPlayerUtility::CBody::MfaocComplete - Checked surfaces supported - Err %d, Surfaces supported %d, Using VPU2 %d", err, iGraphicsSurfaceSupported, iUsingVPU2);
321 if (!iGraphicsSurfaceSupported)
323 if (err != KErrNone && iUsingVPU2)
325 // Set KErrNotSupported if the controller doesn't support graphics surface and
326 // the open source is using CVideoPlayerUtility2
331 SetAndUpdateWindow();
335 SetAndUpdateWindow();
336 #endif // SYMBIAN_BUILD_GCE
338 // now that the controller is open
339 if (iOpenError == KErrNone)
341 iControllerOpen = ETrue;
342 iControllerUid = aControllerUid;
344 #ifdef SYMBIAN_BUILD_GCE
345 // We are using a controller that supports graphics surfaces but are not in surface mode.
346 // Call AddDisplay so we can render to surfaces using the CVideoUtility API.
347 if (iGraphicsSurfaceSupported && !iUsingVPU2)
349 if (iDirectScreenAccess)
351 iDirectScreenAccess->Cancel();
354 // When using surfaces for CVPU we use DoAddDisplayWindowL() which requires clip rectangle and video extent
355 // as arguments. Video extent is not supported by CVPU so aWindowRect is used instead. This function
356 // assumes these args are relative to the window. However they are relative to the display and must be
358 TRect windowRectRelativeToWindow;
359 TRect clipRectRelativeToWindow;
360 ConvertFromRelativeToDisplayToRelativeToWindow(*iWindow, iWindowRect, iClipRect, windowRectRelativeToWindow, clipRectRelativeToWindow);
362 TRAP(iOpenError, DoAddDisplayWindowL(*iWs, iDisplayId, *iWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL));
366 // If an error occurred in any of the above, try for next controller if present
367 // in the selection list.
370 if(iFindAndOpenController->ControllerIndex() < (iFindAndOpenController->ControllerCount())-1)
376 iAsyncCallback->Cancel();
379 if (iControllerEventMonitor)
381 iControllerEventMonitor->Cancel();
383 iOpenError = KErrNone;
392 if(iOpenError != KErrNone && !iControllerOpen)
394 if (iFindAndOpenController)
396 //if try next controller was called when specific controller uid was
397 //given, skip the searching and report error.
398 if(!iFindAndOpenController->StopTryLoadController())
400 if( !(aError == KErrNoMemory || aError == KErrCancel ) )
402 if(iFindAndOpenController->ControllerIndex() < (iFindAndOpenController->ControllerCount())-1)
404 aError = iOpenError; // Actually tries to load controller
405 iOpenError = KErrNone;
413 // if we've already received the open complete event
414 // call the client now (otherwise wait for it)
415 if (iEventOpenReceived || iOpenError != KErrNone)
417 // stop a subsequent HandleEvent(KMMFEventCategoryVideoOpenComplete)
418 // from issuing another callback to client
419 iCallbackOpenReceived = EFalse;
420 iAsyncCallback->Signal(iOpenError, CMMFVideoPlayerCallback::EOpenCompleteEvent);
423 DEBUG_PRINTF("CVideoPlayerUtility::CBody::MfaocComplete--");
426 void CVideoPlayerUtility::CBody::OpenFileL(const TDesC& aFileName, TUid aControllerUid)
428 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filename)++");
429 TMMFileSource filesource(aFileName, KDefaultContentObject, EPlay);
430 OpenFileL(filesource, aControllerUid);
431 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filename)--");
434 void CVideoPlayerUtility::CBody::OpenFileL(const RFile& aFile, TUid aControllerUid)
436 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filehandle)++");
437 RFile& file = const_cast<RFile&>(aFile);
438 TMMFileHandleSource filehandlesource(file, KDefaultContentObject, EPlay);
439 OpenFileL(filehandlesource, aControllerUid);
440 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (filehandle)--");
443 void CVideoPlayerUtility::CBody::OpenFileL(const TMMSource& aSource, TUid aControllerUid)
445 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (source)++");
446 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::OpenFileL - aControllerUid 0x%X", aControllerUid.iUid);
447 // Make sure we are closed
450 iFindAndOpenController->ConfigureSourceSink(
452 CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput));
454 #ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
455 iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
458 if (aControllerUid != KNullUid)
460 iFindAndOpenController->OpenByControllerUid(aControllerUid);
464 iFindAndOpenController->OpenByFileSource(aSource);
467 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenFileL (source)--");
471 // This method launches and initializes plugin controller based on the stream
472 // source header passed in the descriptor buffer.
474 void CVideoPlayerUtility::CBody::OpenDesL(const TDesC8& aDescriptor, TUid aControllerUid)
476 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenDesL++");
477 // Make sure we are closed
480 iFindAndOpenController->ConfigureSourceSink(
481 CMMFFindAndOpenController::TSourceSink(KUidMmfDescriptorSource, CMMFFindAndOpenController::GetConfigDescriptor(aDescriptor)),
482 CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput, KNullDesC8));
484 #ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
485 iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
488 if (aControllerUid!=KNullUid)
490 iFindAndOpenController->OpenByControllerUid(aControllerUid);
494 iFindAndOpenController->OpenByDescriptor(aDescriptor);
496 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenDesL--");
499 void CVideoPlayerUtility::CBody::OpenUrlL(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType, TUid aControllerUid)
501 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenUrlL++");
502 // Make sure we are closed
505 CBufFlat* urlCfgBuffer = NULL;
506 CMMFFindAndOpenController::GetConfigUrlL(urlCfgBuffer, aUrl, aIapId);
508 iFindAndOpenController->ConfigureSourceSink(
509 CMMFFindAndOpenController::TSourceSink(KUidMmfUrlSource, urlCfgBuffer->Ptr(0)),
510 CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput, KNullDesC8));
512 #ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
513 iFindAndOpenController->SetInitScreenNumber(iScreenNumber, &iVideoSetInitScreenCustomCommands);
516 if (aControllerUid!=KNullUid)
518 iFindAndOpenController->OpenByControllerUid(aControllerUid);
521 iFindAndOpenController->OpenByUrl(aUrl, aIapId, aMimeType);
525 DEBUG_PRINTF("CVideoPlayerUtility::CBody::OpenUrlL--");
528 void CVideoPlayerUtility::CBody::Play()
530 DEBUG_PRINTF("CVideoPlayerUtility::CBody::Play++");
531 TInt err = iController.Prime();
533 err = iController.Play();
536 iAsyncCallback->Signal(err,CMMFVideoPlayerCallback::EPlayCompleteEvent);
537 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play (exit 1)-- - Err %d", err);
541 //If Audio Resource Notification request is pending - attempt now
542 if(iArnEventHolder != KNullUid)
544 err = iNotificationRegistrationCommands.RegisterAsClient(iArnEventHolder, iNotificationDataHolder);
545 iArnEventHolder = KNullUid;
546 iNotificationDataHolder = KNullDesC8;
549 iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
552 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play-- - Err %d", err);
555 void CVideoPlayerUtility::CBody::Play(const TTimeIntervalMicroSeconds& aStartTime, const TTimeIntervalMicroSeconds& aEndTime)
557 DEBUG_PRINTF("CVideoPlayerUtility::CBody::Play++");
558 DEBUG_PRINTF3("CVideoPlayerUtility::CBody::Play - aStartTime %ld, aEndTime %ld", aStartTime.Int64(), aEndTime.Int64());
559 TInt err = iController.Prime();
561 err = iVideoPlayControllerCustomCommands.Play(aStartTime, aEndTime);
564 iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
565 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play (exit1)-- - Err %d", err);
569 //If Audio Resource Notification request is pending - attempt now
570 if(iArnEventHolder != KNullUid)
572 err = iNotificationRegistrationCommands.RegisterAsClient(iArnEventHolder, iNotificationDataHolder);
573 iArnEventHolder = KNullUid;
574 iNotificationDataHolder = KNullDesC8;
577 iAsyncCallback->Signal(err, CMMFVideoPlayerCallback::EPlayCompleteEvent);
580 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Play-- - Err %d", err);
584 TInt CVideoPlayerUtility::CBody::Stop()
586 DEBUG_PRINTF("CVideoPlayerUtility::CBody::Stop++");
587 TInt err = iController.Stop();
589 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::Stop-- - Err %d", err);
593 void CVideoPlayerUtility::CBody::PauseL()
595 DEBUG_PRINTF("CVideoPlayerUtility::CBody::PauseL++");
596 User::LeaveIfError(iController.Pause());
598 DEBUG_PRINTF("CVideoPlayerUtility::CBody::PauseL--");
601 void CVideoPlayerUtility::CBody::SetVolumeL(TInt aVolume)
603 User::LeaveIfError(iAudioPlayDeviceCustomCommands.SetVolume(aVolume));
606 void CVideoPlayerUtility::CBody::PrepareDSAL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow)
608 DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL++");
609 CDirectScreenAccess* old = iDirectScreenAccess;
610 iDirectScreenAccess = CDirectScreenAccess::NewL(aWs,aScreenDevice,aWindow,*this);
612 DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL - Starting");
613 iDirectScreenAccess->StartL();
614 DEBUG_PRINTF("CVideoPlayerUtility::CBody::PrepareDSAL--");
617 void CVideoPlayerUtility::CBody::SetDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice,
618 RWindowBase& aWindow, const TRect& aWindowRect,
619 const TRect& aClipRect)
621 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetDisplayWindowL++");
622 DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
623 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
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);
625 DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aWindowRect %d,%d - %d,%d", aWindowRect.iTl.iX, aWindowRect.iTl.iY, aWindowRect.iBr.iX, aWindowRect.iBr.iY);
626 DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetDisplayWindowL - aClipRect %d,%d - %d,%d", aClipRect.iTl.iX, aClipRect.iTl.iY, aClipRect.iBr.iX, aClipRect.iBr.iY);
628 iWindowRect = aWindowRect;
629 iClipRect = aClipRect;
631 #ifdef SYMBIAN_BUILD_GCE
632 // If called from CVideoPlayerUtility2, fail with KErrNotSupport. Otherwise, if the controller supports
633 // the graphics surfaces, it will render to graphics surfaces. If the controller doesn't support
634 // the graphics surfaces, it will use direct screen access.
637 User::Leave(KErrNotSupported);
639 // If the controller does not support GCE or the source has not been opened, start new DSA.
640 if (!iGraphicsSurfaceSupported)
642 PrepareDSAL(aWs, aScreenDevice, aWindow);
645 if (!iGraphicsSurfaceSupported && iControllerOpen)
647 // Set display window and update region, if controller is open
648 User::LeaveIfError(iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect,iClipRect));
649 User::LeaveIfError(iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion()));
652 if (iGraphicsSurfaceSupported && iControllerOpen)
654 // When the controller supports graphics surfaces, need to stop direct screen access.
655 if (iDirectScreenAccess)
657 iDirectScreenAccess->Cancel();
658 AbortNow(RDirectScreenAccess::ETerminateCancel);
661 // When using surfaces for CVPU we use DoAddDisplayWindowL() which requires clip rectangle and video extent
662 // as arguments. Video extent is not supported by CVPU so aWindowRect is used instead. This function
663 // assumes these args are relative to the window. However they are relative to the display and must be
665 TRect windowRectRelativeToWindow;
666 TRect clipRectRelativeToWindow;
667 ConvertFromRelativeToDisplayToRelativeToWindow(aWindow, aWindowRect, aClipRect, windowRectRelativeToWindow, clipRectRelativeToWindow);
669 // check if display for window already exists and if so do an update else create a new display
670 TRAPD(err, CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
673 DoUpdateDisplayWindowL(aWs, aWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL);
677 DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, clipRectRelativeToWindow, windowRectRelativeToWindow, NULL);
681 PrepareDSAL(aWs, aScreenDevice, aWindow);
685 // Set display window and update region, if controller is open
686 User::LeaveIfError(iVideoPlayControllerCustomCommands.SetDisplayWindow(iWindowRect,iClipRect));
687 User::LeaveIfError(iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion()));
688 if(iDirectScreenAccessAbort)
690 User::LeaveIfError(iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EResumeDSA));
691 iDirectScreenAccessAbort = EFalse;
695 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetDisplayWindowL--");
698 TReal32 CVideoPlayerUtility::CBody::VideoFrameRateL() const
700 TReal32 framerate = 0;
701 User::LeaveIfError(iVideoControllerCustomCommands.GetFrameRate(framerate));
706 void CVideoPlayerUtility::CBody::VideoFrameSizeL(TSize& aSize) const
708 User::LeaveIfError(iVideoControllerCustomCommands.GetVideoFrameSize(aSize));
711 TInt CVideoPlayerUtility::CBody::Volume() const
714 iAudioPlayDeviceCustomCommands.GetVolume(vol);
719 void CVideoPlayerUtility::CBody::SetBalanceL(TInt aBalance)
721 User::LeaveIfError(iAudioPlayDeviceCustomCommands.SetBalance(aBalance));
725 TInt CVideoPlayerUtility::CBody::Balance() const
728 iAudioPlayDeviceCustomCommands.GetBalance(bal);
732 void CVideoPlayerUtility::CBody::SetRotationL(TVideoRotation aRotation)
734 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL++");
735 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aRotation %d", aRotation);
737 #ifdef SYMBIAN_BUILD_GCE
738 if (!iGraphicsSurfaceSupported)
740 User::LeaveIfError(iVideoPlayControllerCustomCommands.SetRotation(aRotation));
744 // Rotation setting is not sent to controller when graphics surfaces are used.
745 // If the surface has been created, perform rotation with the help of graphics surfaces;
746 // otherwise, just store the rotation info.
748 TInt count = iActiveDisplays.Count();
750 for (TInt i = 0; i < count; ++i)
752 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
753 CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
754 RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
755 TInt windowcount = windows.Count();
756 for (TInt i = 0; i < windowcount; ++i)
758 CMediaClientVideoDisplayBody::TWindowData& window = windows[i];
759 if (window.iRotation != aRotation)
761 // update config only if setting has actually changed
762 display->SetRotationL(*window.iWindow, aRotation, iCropRegion);
764 if (iSubtitleUtility)
766 TMMFSubtitleWindowConfig config;
767 GetSubtitleConfigFromWindowData(window, config);
769 iSubtitleUtility->UpdateSubtitleConfig(config);
775 iActiveDisplays[i]->SetRotationL(aRotation, iCropRegion);
776 #endif//SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
779 iGlobalRotation = aRotation;
783 User::LeaveIfError(iVideoPlayControllerCustomCommands.SetRotation(aRotation));
784 #endif // SYMBIAN_BUILD_GCE
786 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL--");
789 TVideoRotation CVideoPlayerUtility::CBody::RotationL() const
791 TVideoRotation rot = EVideoRotationNone;
792 #ifdef SYMBIAN_BUILD_GCE
793 if (!iGraphicsSurfaceSupported)
795 User::LeaveIfError(iVideoPlayControllerCustomCommands.GetRotation(rot));
799 // Rotation setting is not retrieved from controller when graphics surfaces are used.
800 rot = iGlobalRotation;
803 User::LeaveIfError(iVideoPlayControllerCustomCommands.GetRotation(rot));
804 #endif // SYMBIAN_BUILD_GCE
808 void CVideoPlayerUtility::CBody::SetScaleFactorL(TReal32 aWidthPercentage, TReal32 aHeightPercentage, TBool aAntiAliasFiltering)
810 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL");
811 DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f, aAntiAliasFiltering %d", aWidthPercentage, aHeightPercentage, aAntiAliasFiltering);
813 #ifdef SYMBIAN_BUILD_GCE
814 if (!iGraphicsSurfaceSupported)
816 User::LeaveIfError(iVideoPlayControllerCustomCommands.SetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
820 // Scale factor setting is not sent to controller when graphics surfaces are used.
821 // If the surface has been created, perform scale factor with the help of graphics surfaces.
822 iAntiAliasFiltering = aAntiAliasFiltering;
823 iGlobalScaleWidth = aWidthPercentage;
824 iGlobalScaleHeight = aHeightPercentage;
825 iGlobalAutoScaleType = EAutoScaleNone;
827 TInt count = iActiveDisplays.Count();
829 for (TInt i = 0; i < count; ++i)
831 iActiveDisplays[i]->SetScaleFactorL(aWidthPercentage, aHeightPercentage, iCropRegion);
835 User::LeaveIfError(iVideoPlayControllerCustomCommands.SetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
836 #endif // SYMBIAN_BUILD_GCE
838 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL--");
841 void CVideoPlayerUtility::CBody::GetScaleFactorL(TReal32& aWidthPercentage, TReal32& aHeightPercentage, TBool& aAntiAliasFiltering) const
843 #ifdef SYMBIAN_BUILD_GCE
844 if (!iGraphicsSurfaceSupported)
846 User::LeaveIfError(iVideoPlayControllerCustomCommands.GetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
850 // Scale factor setting is not retrieved from controller when graphics surfaces are used.
852 aWidthPercentage = iGlobalScaleWidth;
853 aHeightPercentage = iGlobalScaleHeight;
855 aAntiAliasFiltering = iAntiAliasFiltering;
858 User::LeaveIfError(iVideoPlayControllerCustomCommands.GetScaleFactor(aWidthPercentage, aHeightPercentage, aAntiAliasFiltering));
859 #endif // SYMBIAN_BUILD_GCE
862 void CVideoPlayerUtility::CBody::SetCropRegionL(const TRect& aCropRegion)
864 #ifdef SYMBIAN_BUILD_GCE
865 if (!iGraphicsSurfaceSupported)
867 User::LeaveIfError(iVideoPlayControllerCustomCommands.SetCropRegion(aCropRegion));
871 // Crop region setting is not sent to controller when graphics surfaces are used.
872 // If the surface has been created, perform crop region with the help of graphics surfaces;
873 // otherwise, just store the crop region info.
874 if (aCropRegion != iCropRegion)
876 iCropRegion = aCropRegion;
877 User::LeaveIfError(SetAllBackgroundSurfaces());
881 User::LeaveIfError(iVideoPlayControllerCustomCommands.SetCropRegion(aCropRegion));
882 #endif // SYMBIAN_BUILD_GCE
885 void CVideoPlayerUtility::CBody::GetCropRegionL(TRect& aCropRegion) const
887 #ifdef SYMBIAN_BUILD_GCE
888 if (!iGraphicsSurfaceSupported )
890 User::LeaveIfError(iVideoPlayControllerCustomCommands.GetCropRegion(aCropRegion));
894 // Crop rectangle setting is not retrieved from controller when graphics surfaces are used.
895 aCropRegion = iCropRegion;
898 User::LeaveIfError(iVideoPlayControllerCustomCommands.GetCropRegion(aCropRegion));
899 #endif // SYMBIAN_BUILD_GCE
902 void CVideoPlayerUtility::CBody::Prepare()
904 TInt error = iVideoPlayControllerCustomCommands.Prepare();
906 iObserver.MvpuoPrepareComplete(error);
909 const TDesC8& CVideoPlayerUtility::CBody::VideoFormatMimeType() const
911 TPtr8 des = iMimeType->Des();
912 TInt err = iVideoControllerCustomCommands.GetVideoMimeType(des);
919 void CVideoPlayerUtility::CBody::RegisterForVideoLoadingNotification(MVideoLoadingObserver& aObserver)
921 iVideoLoadingObserver = &aObserver;
924 TInt CVideoPlayerUtility::CBody::NumberOfMetaDataEntriesL() const
927 User::LeaveIfError(iController.GetNumberOfMetaDataEntries(num));
932 CMMFMetaDataEntry* CVideoPlayerUtility::CBody::MetaDataEntryL(TInt aMetaDataIndex) const
934 return iController.GetMetaDataEntryL(aMetaDataIndex);
937 void CVideoPlayerUtility::CBody::SetPriorityL(TInt aPriority, TInt aPref)
939 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPriorityL++");
940 DEBUG_PRINTF3("CVideoPlayerUtility::CBody::SetPriorityL - aPriority %d, aPref %d", aPriority, aPref);
942 iPrioritySettings.iPref = aPref;
943 iPrioritySettings.iPriority = aPriority;
945 TInt err = iController.SetPrioritySettings(iPrioritySettings);
946 if ((err == KErrNone) || (err == KErrNotReady))
948 iFindAndOpenController->Configure(KUidMediaTypeVideo, iPrioritySettings, CMMFPluginSelectionParameters::EAllowOtherMediaIds);
954 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPriorityL--");
957 void CVideoPlayerUtility::CBody::PriorityL(TInt & aPriority, TMdaPriorityPreference &aPref) const
959 aPriority = iPrioritySettings.iPriority;
960 aPref = TMdaPriorityPreference(iPrioritySettings.iPref);
964 void CVideoPlayerUtility::CBody::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
966 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPositionL++");
967 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetPositionL - aPosition %ld", aPosition.Int64());
968 User::LeaveIfError(iController.SetPosition(aPosition));
969 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetPositionL--");
973 TTimeIntervalMicroSeconds CVideoPlayerUtility::CBody::DurationL() const
975 TTimeIntervalMicroSeconds duration;
976 User::LeaveIfError(iController.GetDuration(duration));
980 TTimeIntervalMicroSeconds CVideoPlayerUtility::CBody::PositionL() const
982 TTimeIntervalMicroSeconds position;
983 User::LeaveIfError(iController.GetPosition(position));
987 TInt CVideoPlayerUtility::CBody::MaxVolume() const
990 iAudioPlayDeviceCustomCommands.GetMaxVolume(maxVol);
994 void CVideoPlayerUtility::CBody::GetFrameL(TDisplayMode aDisplayMode, TBool aUseIntentAPI, TIntent aIntent)
998 iFrameBitmap = new (ELeave) CFbsBitmap;
999 User::LeaveIfError(iFrameBitmap->Create(TSize(0,0),aDisplayMode));
1001 iFrameCallback->SetFrame(*iFrameBitmap);
1005 iVideoDRMExtCustomCommands.GetFrame(*iFrameBitmap, aIntent, iFrameCallback->ActiveStatus());
1009 iVideoPlayControllerCustomCommands.GetFrame(*iFrameBitmap, iFrameCallback->ActiveStatus());
1013 MMMFDRMCustomCommand* CVideoPlayerUtility::CBody::GetDRMCustomCommand()
1015 // XXX: check controller supports MMMFDRMCustomCommandImplementor
1016 TInt error = iDRMCustomCommands.EvaluateIntent(ContentAccess::EPeek);
1017 if (error==KErrNone)
1019 return static_cast<MMMFDRMCustomCommand*>(&iDRMCustomCommands);
1027 TInt CVideoPlayerUtility::CBody::VideoBitRateL() const
1030 User::LeaveIfError(iVideoControllerCustomCommands.GetVideoBitRate(bitRate));
1034 TInt CVideoPlayerUtility::CBody::AudioBitRateL() const
1037 User::LeaveIfError(iVideoControllerCustomCommands.GetAudioBitRate(bitRate));
1041 TBool CVideoPlayerUtility::CBody::AudioEnabledL() const
1044 User::LeaveIfError(iVideoPlayControllerCustomCommands.GetAudioEnabled(enabled));
1049 void CVideoPlayerUtility::CBody::RefreshFrameL()
1051 User::LeaveIfError(iVideoPlayControllerCustomCommands.RefreshFrame());
1054 TFourCC CVideoPlayerUtility::CBody::AudioTypeL() const
1057 User::LeaveIfError(iVideoControllerCustomCommands.GetAudioCodec(codec));
1062 void CVideoPlayerUtility::CBody::HandleEvent(const TMMFEvent& aEvent)
1064 DEBUG_PRINTF("CVideoPlayerUtility::CBody::HandleEvent++");
1065 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::HandleEvent - Event type 0x%X", aEvent.iEventType);
1067 if (aEvent.iEventType == KMMFEventCategoryVideoOpenComplete)
1069 // if we haven't had a MfaocComplete() callback yet,
1070 // we need to delay the call back to the client
1071 // because the source/sink will not have been opened yet.
1072 iEventOpenReceived = ETrue;
1073 if (iOpenError == KErrNone)
1074 iOpenError = aEvent.iErrorCode;
1075 if (iCallbackOpenReceived)
1076 iObserver.MvpuoOpenComplete(aEvent.iErrorCode);
1078 else if (aEvent.iEventType == KMMFEventCategoryVideoPrepareComplete)
1080 iObserver.MvpuoPrepareComplete(aEvent.iErrorCode);
1082 else if (aEvent.iEventType == KMMFEventCategoryPlaybackComplete)
1084 iObserver.MvpuoPlayComplete(aEvent.iErrorCode);
1086 else if (aEvent.iEventType == KMMFEventCategoryVideoLoadingStarted)
1088 if (iVideoLoadingObserver)
1089 iVideoLoadingObserver->MvloLoadingStarted();
1091 else if (aEvent.iEventType == KMMFEventCategoryVideoLoadingComplete)
1093 if (iVideoLoadingObserver)
1094 iVideoLoadingObserver->MvloLoadingComplete();
1096 else if(aEvent.iEventType == KMMFEventCategoryAudioResourceAvailable)
1098 if(iAudioResourceNotificationCallBack != NULL)
1100 TBuf8<TMMFAudioConfig::KNotificationDataBufferSize> notificationData;
1101 if (KErrNone != iNotificationRegistrationCommands.GetResourceNotificationData(aEvent.iEventType, notificationData))
1103 notificationData.SetLength(0);
1105 iAudioResourceNotificationCallBack->MarncResourceAvailable(aEvent.iEventType, notificationData);
1108 #ifdef SYMBIAN_BUILD_GCE
1109 else if(aEvent.iEventType == KMMFEventCategoryVideoSurfaceCreated)
1111 TInt error = SurfaceCreated();
1113 if (error != KErrNone)
1115 // Send error to the client
1116 TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
1117 iObserver.MvpuoEvent(generalError);
1120 else if(aEvent.iEventType == KMMFEventCategoryVideoSurfaceParametersChanged)
1122 TInt error = SurfaceParametersChanged();
1124 if (error != KErrNone)
1126 // Send error to the client
1127 TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
1128 iObserver.MvpuoEvent(generalError);
1131 else if(aEvent.iEventType == KMMFEventCategoryVideoRemoveSurface)
1133 // Check surface is created
1134 TInt error = RemoveSurface(ETrue);
1136 if (error != KErrNone)
1138 // Send error to the client
1139 TMMFEvent generalError(KMMFEventCategoryVideoPlayerGeneralError, error);
1140 iObserver.MvpuoEvent(generalError);
1143 #endif // SYMBIAN_BUILD_GCE
1144 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1145 else if(aEvent.iEventType == KMMFEventCategoryVideoSubtitleCrpReady)
1147 if (iSubtitleUtility)
1149 // subtitle has not been disabled before event arrive
1150 RWindow* window = FindWindowWithWsHandle(iActiveDisplays, aEvent.iErrorCode);
1153 // window has not been removed before event arrive
1154 iSubtitleUtility->HandleCrpReady(*window);
1158 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1160 // Pass on all unrecognised events to the client
1161 iObserver.MvpuoEvent(aEvent);
1163 DEBUG_PRINTF("CVideoPlayerUtility::CBody::HandleEvent--");
1166 #ifdef SYMBIAN_BUILD_GCE
1167 TInt CVideoPlayerUtility::CBody::SurfaceCreated()
1169 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceCreated++");
1171 TInt count = iActiveDisplays.Count();
1172 TBool replaceSurface = !(iSurfaceId.IsNull());
1173 TSurfaceId oldSurfaceId(iSurfaceId);
1175 // first remove surface if one already in use
1178 for (TInt i = 0; i < count; i++)
1180 CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
1181 display->RemoveSurface(EFalse);
1183 iSurfaceId = TSurfaceId::CreateNullId();
1186 TSurfaceId surfaceId;
1188 TVideoAspectRatio aspectRatio;
1190 TInt error = iVideoPlaySurfaceSupportCustomCommands.GetSurfaceParameters(surfaceId,
1193 if(error != KErrNone)
1198 iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(oldSurfaceId);
1203 // loop through all displays, if any fail continue and report error later
1205 for (TInt i = 0; i < count; ++i)
1207 error2 = iActiveDisplays[i]->SurfaceCreated(surfaceId, cropRect, aspectRatio, iCropRegion);
1208 if(error2 != KErrNone)
1214 // now store surface details
1215 iSurfaceId = surfaceId;
1216 iSurfaceCropRect = cropRect;
1217 iAspectRatio = aspectRatio;
1219 // if surface already existed tell video adaptation it is no longer in use. Video adaptation
1220 // will remove the surface when it receives this call therefore the following code must be done at the
1221 // end of this function.
1224 error2 = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(oldSurfaceId);
1225 if (error2 != KErrNone)
1231 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceCreated--");
1235 TInt CVideoPlayerUtility::CBody::SurfaceParametersChanged()
1237 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SurfaceParametersChanged++");
1238 if (iSurfaceId.IsNull())
1240 return KErrNotSupported;
1243 TSurfaceId surfaceId;
1245 TVideoAspectRatio aspectRatio;
1247 TInt error = iVideoPlaySurfaceSupportCustomCommands.GetSurfaceParameters(surfaceId,
1250 if (error != KErrNone)
1255 if (iSurfaceId != surfaceId)
1260 TInt count = iActiveDisplays.Count();
1261 TInt error2 = KErrNone;
1262 for (TInt i = 0; i < count; ++i)
1264 error2 = iActiveDisplays[i]->SurfaceParametersChanged(surfaceId, cropRect, aspectRatio);
1266 // Save the error for the first failure only
1267 if ((error2 != KErrNone) && (error == KErrNone))
1272 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SurfaceParametersChanged-- - Error %d", error);
1276 TInt CVideoPlayerUtility::CBody::SetAllBackgroundSurfaces()
1278 TInt count = iActiveDisplays.Count();
1279 TInt err = KErrNone;
1281 for (TInt i = 0; i < count; ++i)
1283 CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
1284 err = display->RedrawWindows(iCropRegion);
1286 if (err != KErrNone)
1294 TInt CVideoPlayerUtility::CBody::RemoveSurface(TBool aControllerEvent)
1296 DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveSurface++");
1297 if (iSurfaceId.IsNull())
1299 return KErrNotFound;
1302 TInt count = iActiveDisplays.Count();
1303 for (TInt i = 0; i < count; i++)
1305 iActiveDisplays[i]->RemoveSurface(aControllerEvent);
1308 TInt error = iVideoPlaySurfaceSupportCustomCommands.SurfaceRemoved(iSurfaceId);
1310 iSurfaceId = TSurfaceId::CreateNullId();
1312 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveSurface-- - Error %d", error);
1316 #endif // SYMBIAN_BUILD_GCE
1318 void CVideoPlayerUtility::CBody::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
1320 if (iControllerOpen)
1322 iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EAbortDSA);
1323 iDirectScreenAccessAbort = ETrue;
1327 void CVideoPlayerUtility::CBody::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/)
1329 __ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument)); // should always be valid if we have a callback from it
1330 TRAPD( err, iDirectScreenAccess->StartL());
1332 if (iControllerOpen)
1334 if (err == KErrNone)
1336 iVideoPlayControllerCustomCommands.UpdateDisplayRegion(*iDirectScreenAccess->DrawingRegion());
1337 iVideoPlayControllerCustomCommands.DirectScreenAccessEvent(EResumeDSA);
1342 TInt CVideoPlayerUtility::CBody::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom)
1344 return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom);
1347 TInt CVideoPlayerUtility::CBody::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2)
1349 return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2);
1352 void CVideoPlayerUtility::CBody::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus)
1354 iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom, aStatus);
1357 void CVideoPlayerUtility::CBody::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus)
1359 iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aStatus);
1362 void CVideoPlayerUtility::CBody::SetVideoFrameRateL(TReal32 aFramesPerSecond)
1364 User::LeaveIfError(iVideoControllerCustomCommands.SetFrameRate(aFramesPerSecond));
1367 const CMMFControllerImplementationInformation& CVideoPlayerUtility::CBody::ControllerImplementationInformationL()
1369 if (!iControllerImplementationInformation)
1371 if (iControllerUid==KNullUid)
1372 User::Leave(KErrNotReady);
1373 iControllerImplementationInformation = CMMFControllerImplementationInformation::NewL(iControllerUid);
1375 return *iControllerImplementationInformation;
1378 void CVideoPlayerUtility::CBody::GetVideoLoadingProgressL(TInt& aPercentageProgress)
1380 User::LeaveIfError(iVideoPlayControllerCustomCommands.GetLoadingProgress(aPercentageProgress));
1383 void CVideoPlayerUtility::CBody::StopDirectScreenAccessL()
1385 #ifdef SYMBIAN_BUILD_GCE
1388 User::Leave(KErrNotSupported);
1391 if (!iGraphicsSurfaceSupported)
1393 __ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument));
1394 iDirectScreenAccess->Cancel();
1395 AbortNow(RDirectScreenAccess::ETerminateCancel);
1398 __ASSERT_ALWAYS(iDirectScreenAccess, User::Panic(_L("iDirectScreenAccess is NULL"), KErrArgument));
1399 iDirectScreenAccess->Cancel();
1400 AbortNow(RDirectScreenAccess::ETerminateCancel);
1401 #endif // SYMBIAN_BUILD_GCE
1404 void CVideoPlayerUtility::CBody::StartDirectScreenAccessL()
1406 #ifdef SYMBIAN_BUILD_GCE
1409 User::Leave(KErrNotSupported);
1412 if (!iGraphicsSurfaceSupported)
1414 // ETerminateCancel is a dummy value that is ignored by Restart()
1415 Restart(RDirectScreenAccess::ETerminateCancel);
1418 // ETerminateCancel is a dummy value that is ignored by Restart()
1419 Restart(RDirectScreenAccess::ETerminateCancel);
1420 #endif // SYMBIAN_BUILD_GCE
1423 //registers for notification when audio resource is available.
1424 TInt CVideoPlayerUtility::CBody::RegisterAudioResourceNotification( MMMFAudioResourceNotificationCallback& aCallback,
1425 TUid aNotificationEventUid,
1426 const TDesC8& aNotificationRegistrationData)
1428 //if not valid notification event id, return;
1429 if(aNotificationEventUid != KMMFEventCategoryAudioResourceAvailable)
1431 return KErrNotSupported;
1434 iAudioResourceNotificationCallBack = &aCallback;
1435 TInt err = iNotificationRegistrationCommands.RegisterAsClient(aNotificationEventUid, aNotificationRegistrationData);
1436 if(err == KErrNotReady)
1438 //save the request - so that registration can be attempted on play
1439 iArnEventHolder = aNotificationEventUid;
1440 iNotificationDataHolder = aNotificationRegistrationData;
1443 iArnEventHolder = KNullUid;
1444 iNotificationDataHolder = KNullDesC8;
1448 //Cancels the registration for audio resource notification.
1449 TInt CVideoPlayerUtility::CBody::CancelRegisterAudioResourceNotification(TUid aNotificationEventId)
1451 //if not valid notification event id, return;
1452 if(aNotificationEventId != KMMFEventCategoryAudioResourceAvailable)
1454 return KErrNotSupported;
1456 TInt err = iNotificationRegistrationCommands.CancelRegisterAsClient(aNotificationEventId);
1457 if(err == KErrNotReady)
1459 if(iArnEventHolder == KNullUid)
1463 //iArnEventHolder has data to re-attempt registration ;
1464 //but reattempt is not made(which is done in play);hence return KErrNone
1465 iArnEventHolder = KNullUid;
1466 iNotificationDataHolder = KNullDesC8;
1472 //Waits for the client to resume the play even after the default timer expires.
1473 TInt CVideoPlayerUtility::CBody::WillResumePlay()
1475 return iNotificationRegistrationCommands.WillResumePlay();
1478 // This method will fail with KErrNotSupported when using CVideoPlayerUtility2, otherwise
1479 // set the screen number.
1480 TInt CVideoPlayerUtility::CBody::SetInitScreenNumber(TInt aScreenNumber)
1482 #ifdef SYMBIAN_BUILD_GCE
1483 // If the method is called from CVideoPlayerUtility2, return KErrNotSupport
1486 return KErrNotSupported;
1490 #ifdef SYMBIAN_ENABLE_MMF_MULTISCREEN_SUPPORT
1491 iScreenNumber = aScreenNumber;
1494 aScreenNumber = aScreenNumber;//added to remove the warning
1495 return KErrNotSupported;
1499 #ifdef SYMBIAN_BUILD_GCE
1500 //-------------------------------------------------------------------------------
1502 void CVideoPlayerUtility::CBody::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice,
1503 RWindow& aWindow, const TRect& aVideoExtent,
1504 const TRect& aWindowClipRect)
1506 DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL++");
1507 DEBUG_PRINTF4("CVideoPlayerUtility::CBody::AddDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
1508 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
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);
1510 DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
1511 DEBUG_PRINTF5("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
1513 // set window and get display ID for the window
1514 TRect windowRect = TRect(aWindow.Size());
1516 // Check the rectangle is contained completely within the window
1517 if (!RectContains(windowRect, aWindowClipRect))
1519 // NOTE: TRect::Contains() is not used for comparison here as point located on the right hand
1520 // side or bottom is considered to be outside the rectangle, which is not the desirable
1521 // behaviour in this case
1522 User::Leave(KErrArgument);
1525 DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, aWindowClipRect, aVideoExtent, &aWindow);
1526 DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL--");
1529 void CVideoPlayerUtility::CBody::AddDisplayWindowL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
1531 DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL++");
1532 DEBUG_PRINTF4("CVideoPlayerUtility::CBody::AddDisplayWindowL - aScreenDevice num %d, width %d, height %d", aScreenDevice.GetScreenNumber(), aScreenDevice.SizeInPixels().iWidth, aScreenDevice.SizeInPixels().iHeight);
1533 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayWindowL - aWindow WsHandle 0x%X", aWindow.WsHandle());
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);
1536 DoAddDisplayWindowL(aWs, aScreenDevice.GetScreenNumber(), aWindow, TRect(aWindow.Size()), TRect(aWindow.Size()), &aWindow);
1538 DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayWindowL--");
1541 void CVideoPlayerUtility::CBody::DoAddDisplayWindowL(RWsSession& aWs, TInt aDisplayId, RWindowBase& aWindow,
1542 const TRect& aClipRect, const TRect& aVideoExtent, RWindow* aWindow2)
1546 // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
1547 if (!iControllerOpen)
1549 User::Leave(KErrNotReady);
1552 // make sure window isn't already added on another display
1553 TRAPD(err, CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
1554 if (err != KErrNotFound)
1556 // If err is something else but KErrNone leave
1557 User::LeaveIfError(err);
1558 // Window is already in use
1559 User::Leave(KErrInUse);
1562 TInt pos = iActiveDisplays.FindInOrder(aDisplayId, CMediaClientVideoDisplayBody::CompareByDisplay);
1563 CMediaClientVideoDisplayBody* display = NULL;
1565 if (pos == KErrNotFound)
1567 if(iSurfaceId.IsNull())
1569 display = CMediaClientVideoDisplayBody::NewL(aDisplayId, ETrue);
1573 display = CMediaClientVideoDisplayBody::NewL(aDisplayId, iSurfaceId, iSurfaceCropRect, iAspectRatio, ETrue);
1575 CleanupStack::PushL(display);
1576 iActiveDisplays.InsertInOrderL(display, CMediaClientVideoDisplayBody::Compare);
1577 CleanupStack::Pop(display);
1581 User::LeaveIfError(pos);
1582 display = iActiveDisplays[pos];
1585 display->AddDisplayWindowL(&aWindow, aClipRect, iCropRegion, aVideoExtent, iGlobalScaleWidth, iGlobalScaleHeight,
1586 iGlobalRotation, iGlobalAutoScaleType, iGlobalHorizPos, iGlobalVertPos, aWindow2);
1588 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1589 if (iSubtitleUtility)
1591 // subtitles were enabled already, so enable subtitles on this window
1592 TMMFSubtitleWindowConfig config;
1593 config.iWindowId = aWindow.WsHandle();
1594 config.iWindowClipRect = aClipRect;
1595 config.iDisplayMode = aWindow.DisplayMode();
1596 config.iRotation = iGlobalRotation;
1597 iSubtitleUtility->AddSubtitleConfig(config); // ignore error from add subtitle config because the window can still display video properly
1599 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1602 void CVideoPlayerUtility::CBody::DoUpdateDisplayWindowL(RWsSession& aWs, RWindowBase& aWindow,
1603 const TRect& aClipRect, const TRect& aVideoExtent, RWindow* aWindow2)
1607 // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
1608 if (!iControllerOpen)
1610 User::Leave(KErrNotReady);
1613 CMediaClientVideoDisplayBody* display = NULL;
1614 TRAPD(err, display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
1615 User::LeaveIfError(err);
1617 display->UpdateDisplayWindowL(&aWindow, aClipRect, iCropRegion, aVideoExtent, iGlobalScaleWidth, iGlobalScaleHeight,
1618 iGlobalRotation, iGlobalAutoScaleType, iGlobalHorizPos, iGlobalVertPos, aWindow2);
1620 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1621 if (iSubtitleUtility)
1623 // subtitles were enabled already, so update subtitles on this window
1624 TMMFSubtitleWindowConfig config;
1625 config.iWindowId = aWindow.WsHandle();
1626 config.iWindowClipRect = aClipRect;
1627 config.iDisplayMode = aWindow.DisplayMode();
1628 config.iRotation = iGlobalRotation;
1629 iSubtitleUtility->UpdateSubtitleConfig(config); // ignore error from add subtitle config because the window can still display video properly
1631 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1634 void CVideoPlayerUtility::CBody::RemoveDisplayWindow(RWindowBase& aWindow)
1636 DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplayWindow++");
1637 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveDisplayWindow - aWindow WsHandle 0x%X", aWindow.WsHandle());
1639 CMediaClientVideoDisplayBody* display = NULL;
1640 TRAPD(err, display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow));
1642 if (err == KErrNone)
1644 display->RemoveDisplayWindow(aWindow);
1646 if (!display->IsUsed())
1649 TInt pos = iActiveDisplays.Find(display);
1650 iActiveDisplays.Remove(pos);
1654 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1655 if (iSubtitleUtility)
1657 // subtitles are enabled, so remove window config, ignore error
1658 iSubtitleUtility->RemoveSubtitleConfig(aWindow.WsHandle());
1660 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1662 DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplayWindow--");
1665 void CVideoPlayerUtility::CBody::AddDisplayL(TInt aDisplay, MMMFSurfaceEventHandler& aEventHandler)
1667 DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayL");
1668 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::AddDisplayL - aDisplay %d", aDisplay);
1669 if (!iControllerOpen)
1671 User::Leave(KErrNotReady);
1674 TInt err = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
1676 if (err == KErrNotFound)
1678 CMediaClientVideoDisplayBody* display;
1679 if(iSurfaceId.IsNull())
1681 display = CMediaClientVideoDisplayBody::NewL(aDisplay, ETrue);
1685 display = CMediaClientVideoDisplayBody::NewL(aDisplay, iSurfaceId, iSurfaceCropRect, iAspectRatio, ETrue);
1687 CleanupStack::PushL(display);
1688 iActiveDisplays.InsertInOrderL(display, CMediaClientVideoDisplayBody::Compare);
1689 CleanupStack::Pop(display);
1690 display->AddDisplayL(aEventHandler);
1694 User::LeaveIfError(err);
1695 iActiveDisplays[err]->AddDisplayL(aEventHandler);
1697 DEBUG_PRINTF("CVideoPlayerUtility::CBody::AddDisplayL--");
1700 void CVideoPlayerUtility::CBody::RemoveDisplay(TInt aDisplay)
1702 DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplay++");
1703 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::RemoveDisplay - aDisplay %d", aDisplay);
1704 TInt pos = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
1706 if (pos >= KErrNone)
1708 CMediaClientVideoDisplayBody* disp = iActiveDisplays[pos];
1709 disp->RemoveDisplay();
1711 if (!disp->HasWindows())
1713 iActiveDisplays.Remove(pos);
1717 DEBUG_PRINTF("CVideoPlayerUtility::CBody::RemoveDisplay--");
1720 void CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow(
1721 const RWindowBase& aWindow,
1722 const TRect& aFromWindowRect,
1723 const TRect& aFromClipRect,
1724 TRect& aToWindowRect,
1727 DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow++");
1728 TPoint windowOrigin = aWindow.AbsPosition();
1731 aToWindowRect.iTl.iX = aFromWindowRect.iTl.iX - windowOrigin.iX;
1732 aToWindowRect.iTl.iY = aFromWindowRect.iTl.iY - windowOrigin.iY;
1733 aToWindowRect.iBr.iX = aFromWindowRect.iBr.iX - windowOrigin.iX;
1734 aToWindowRect.iBr.iY = aFromWindowRect.iBr.iY - windowOrigin.iY;
1737 aToClipRect.iTl.iX = aFromClipRect.iTl.iX - windowOrigin.iX;
1738 aToClipRect.iTl.iY = aFromClipRect.iTl.iY - windowOrigin.iY;
1739 aToClipRect.iBr.iX = aFromClipRect.iBr.iX - windowOrigin.iX;
1740 aToClipRect.iBr.iY = aFromClipRect.iBr.iY - windowOrigin.iY;
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);
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);
1744 DEBUG_PRINTF("CVideoPlayerUtility::CBody::ConvertFromRelativeToDisplayToRelativeToWindow--");
1747 void CVideoPlayerUtility::CBody::SetVideoExtentL(const RWindowBase& aWindow, const TRect& aVideoExtent)
1749 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetVideoExtentL++");
1750 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetVideoExtentL - aWindow WsHandle 0x%X", aWindow.WsHandle());
1751 DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetVideoExtentL - aVideoExtent %d,%d - %d,%d", aVideoExtent.iTl.iX, aVideoExtent.iTl.iY, aVideoExtent.iBr.iX, aVideoExtent.iBr.iY);
1753 // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
1754 if (!iControllerOpen)
1756 User::Leave(KErrNotReady);
1759 CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
1760 display->SetVideoExtentL(aWindow, aVideoExtent, iCropRegion);
1762 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetVideoExtentL--");
1765 void CVideoPlayerUtility::CBody::SetWindowClipRectL(const RWindowBase& aWindow, const TRect& aWindowClipRect)
1767 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetWindowClipRectL++");
1768 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetWindowClipRectL - aWindow WsHandle 0x%X", aWindow.WsHandle());
1769 DEBUG_PRINTF5("CVideoPlayerUtility::CBody::SetWindowClipRectL - aWindowClipRect %d,%d - %d,%d", aWindowClipRect.iTl.iX, aWindowClipRect.iTl.iY, aWindowClipRect.iBr.iX, aWindowClipRect.iBr.iY);
1771 // check opening the source is complete and the client has been recieved an MvpuoOpenComplete() callback
1772 if (!iControllerOpen)
1774 User::Leave(KErrNotReady);
1777 TRect winRect(aWindow.Size());
1779 if (!RectContains(winRect, aWindowClipRect))
1781 User::Leave(KErrArgument);
1784 CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
1785 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1786 RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
1787 TInt pos = windows.Find(aWindow.WsHandle(), CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
1788 User::LeaveIfError(pos);
1790 CMediaClientVideoDisplayBody::TWindowData& currentWin = windows[pos];
1791 if (currentWin.iClipRect != aWindowClipRect)
1793 // update config only if setting has actually changed
1794 display->SetWindowClipRectL(aWindow, aWindowClipRect, iCropRegion);
1796 if (iSubtitleUtility)
1798 TMMFSubtitleWindowConfig config;
1799 GetSubtitleConfigFromWindowData(currentWin, config);
1801 iSubtitleUtility->UpdateSubtitleConfig(config);
1805 display->SetWindowClipRectL(aWindow, aWindowClipRect, iCropRegion);
1806 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1808 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetWindowClipRectL--");
1811 // Check if the controller supports the graphics surface. Has to be called after resource opened.
1812 TInt CVideoPlayerUtility::CBody::CheckSurfaceSupported()
1814 TInt err = iFindAndOpenController->SurfaceSupported();
1816 if (err == KErrNone)
1818 iGraphicsSurfaceSupported = ETrue;
1822 iGraphicsSurfaceSupported = EFalse;
1828 TBool CVideoPlayerUtility::CBody::RectContains(const TRect& aLeft, const TRect& aRight)
1830 return !(aLeft.iTl.iX > aRight.iTl.iX ||
1831 aLeft.iTl.iY > aRight.iTl.iY ||
1832 aLeft.iBr.iX < aRight.iBr.iX ||
1833 aLeft.iBr.iY < aRight.iBr.iY);
1837 void CVideoPlayerUtility::CBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType)
1839 SetAutoScaleL(aWindow, aScaleType, EHorizontalAlignCenter, EVerticalAlignCenter);
1842 void CVideoPlayerUtility::CBody::SetAutoScaleL(const RWindowBase& aWindow, TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
1844 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL++");
1845 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetAutoScaleL - aWindow WsHandle 0x%X", aWindow.WsHandle());
1846 DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetAutoScaleL - aScaleType %d, aHorizPos %d, aVertPos %d", aScaleType, aHorizPos, aVertPos);
1848 if (!iControllerOpen)
1850 User::Leave(KErrNotReady);
1853 CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
1854 display->SetAutoScaleL(aWindow, aScaleType, aHorizPos, aVertPos, iCropRegion);
1856 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL--");
1859 void CVideoPlayerUtility::CBody::SetRotationL(const RWindowBase& aWindow, TVideoRotation aRotation)
1861 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL++");
1862 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aWindow WsHandle 0x%X", aWindow.WsHandle());
1863 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetRotationL - aRotation %d", aRotation);
1865 if (!iControllerOpen)
1867 User::Leave(KErrNotReady);
1870 CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
1871 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1872 RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
1873 TInt pos = windows.Find(aWindow.WsHandle(), CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
1874 User::LeaveIfError(pos);
1876 CMediaClientVideoDisplayBody::TWindowData& currentWin = windows[pos];
1877 if (currentWin.iRotation != aRotation)
1879 display->SetRotationL(aWindow, aRotation, iCropRegion);
1881 if (iSubtitleUtility)
1883 TMMFSubtitleWindowConfig config;
1884 GetSubtitleConfigFromWindowData(currentWin, config);
1886 iSubtitleUtility->UpdateSubtitleConfig(config);
1890 display->SetRotationL(aWindow, aRotation, iCropRegion);
1891 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
1892 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetRotationL--");
1895 TVideoRotation CVideoPlayerUtility::CBody::RotationL(const RWindowBase& aWindow) const
1897 if (!iControllerOpen)
1899 User::Leave(KErrNotReady);
1901 CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
1902 return display->RotationL(aWindow);
1905 void CVideoPlayerUtility::CBody::SetScaleFactorL(const RWindowBase& aWindow, TReal32 aWidthPercentage, TReal32 aHeightPercentage)
1907 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL++");
1908 DEBUG_PRINTF2("CVideoPlayerUtility::CBody::SetScaleFactorL - aWindow WsHandle 0x%X", aWindow.WsHandle());
1909 DEBUG_PRINTF3("CVideoPlayerUtility::CBody::SetScaleFactorL - aWidthPercentage %f, aHeightPercentage %f", aWidthPercentage, aHeightPercentage);
1910 if (!iControllerOpen)
1912 User::Leave(KErrNotReady);
1915 CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
1916 display->SetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage, iCropRegion);
1917 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetScaleFactorL--");
1920 void CVideoPlayerUtility::CBody::GetScaleFactorL(const RWindowBase& aWindow, TReal32& aWidthPercentage, TReal32& aHeightPercentage) const
1922 if (!iControllerOpen)
1924 User::Leave(KErrNotReady);
1927 CMediaClientVideoDisplayBody* display = CMediaClientVideoDisplayBody::FindDisplayWithWindowL(iActiveDisplays, aWindow);
1928 display->GetScaleFactorL(aWindow, aWidthPercentage, aHeightPercentage);
1931 void CVideoPlayerUtility::CBody::SetExternalDisplaySwitchingL(TInt aDisplay, TBool aControl)
1933 TInt pos = iActiveDisplays.FindInOrder(aDisplay, CMediaClientVideoDisplayBody::CompareByDisplay);
1935 User::LeaveIfError(pos);
1937 iActiveDisplays[pos]->SetExternalDisplaySwitchingL(aControl);
1940 #endif // SYMBIAN_BUILD_GCE
1942 void CVideoPlayerUtility::CBody::SetPlayVelocityL(TInt aVelocity)
1944 // Leave if Open is not yet called on controller.
1945 if(!iEventOpenReceived)
1947 User::Leave(KErrNotReady);
1950 User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetPlayVelocity(aVelocity));
1953 const TInt KDefaultPlayVelocity = 100;
1955 TInt CVideoPlayerUtility::CBody::PlayVelocityL() const
1960 // Leave if Open is not yet called.
1961 if( !iEventOpenReceived )
1963 User::Leave(KErrNotReady);
1966 error = iVideoPlayControllerExtCustomCommands.PlayVelocity(velocity);
1967 /* if customcommand is not implemented by controller pluggin return default value(100) */
1968 if (KErrNotSupported == error)
1970 velocity = KDefaultPlayVelocity;
1974 User::LeaveIfError( error );
1978 void CVideoPlayerUtility::CBody::StepFrameL(TInt aStep)
1980 //Leave if not in paused state. This functionality is supported only in paused state.
1981 if( (!iEventOpenReceived ) || ( EPaused != iState ) )
1983 User::Leave(KErrNotReady);
1986 User::LeaveIfError(iVideoPlayControllerExtCustomCommands.StepFrame(aStep));
1988 void CVideoPlayerUtility::CBody::GetPlayRateCapabilitiesL(TVideoPlayRateCapabilities& aCapabilities) const
1992 // Leave if Open is not yet called on controller.
1993 if( !iEventOpenReceived )
1995 User::Leave(KErrNotReady);
1998 error = iVideoPlayControllerExtCustomCommands.GetPlayRateCapabilities(aCapabilities);
1999 /* if customcommand is not implemented by controller pluggin return not supported */
2000 if (KErrNotSupported == error)
2002 aCapabilities.iPlayBackward = EFalse;
2003 aCapabilities.iPlayForward = EFalse;
2004 aCapabilities.iStepBackward = EFalse;
2005 aCapabilities.iStepForward = EFalse;
2009 User::LeaveIfError(error);
2012 void CVideoPlayerUtility::CBody::SetVideoEnabledL(TBool aVideoEnabled)
2014 // Leave if Open is not yet called or not in stopped state.
2015 if( (!iEventOpenReceived ) || ( EStopped != iState ) )
2017 User::Leave(KErrNotReady);
2020 User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetVideoEnabled(aVideoEnabled));
2022 TBool CVideoPlayerUtility::CBody::VideoEnabledL() const
2027 // Leave if Open is not yet called.
2028 if( !iEventOpenReceived )
2030 User::Leave(KErrNotReady);
2033 error = iVideoPlayControllerExtCustomCommands.VideoEnabled(videoEnabled);
2034 /* if customcommand is not implemented by controller pluggin return default value ETrue */
2035 if (KErrNotSupported == error)
2037 videoEnabled = ETrue;
2041 User::LeaveIfError(error);
2043 return videoEnabled;
2045 void CVideoPlayerUtility::CBody::SetAudioEnabledL(TBool aAudioEnabled)
2047 // Leave if Open is not yet called or not in stopped state.
2048 if( (!iEventOpenReceived ) || ( EStopped != iState ) )
2050 User::Leave(KErrNotReady);
2053 User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAudioEnabled(aAudioEnabled));
2055 void CVideoPlayerUtility::CBody::SetAutoScaleL(TAutoScaleType aScaleType)
2057 SetAutoScaleL(aScaleType, EHorizontalAlignCenter, EVerticalAlignCenter);
2059 void CVideoPlayerUtility::CBody::SetAutoScaleL(TAutoScaleType aScaleType, TInt aHorizPos, TInt aVertPos)
2061 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL++");
2062 DEBUG_PRINTF4("CVideoPlayerUtility::CBody::SetAutoScaleL - aScaleType %d, aHorizPos %d, aVertPos %d", aScaleType, aHorizPos, aVertPos);
2064 // Leave if Open is not yet called.
2065 if(!iEventOpenReceived )
2067 User::Leave(KErrNotReady);
2070 #ifdef SYMBIAN_BUILD_GCE
2071 if (!iGraphicsSurfaceSupported)
2073 User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAutoScale(aScaleType, aHorizPos, aVertPos));
2077 // Auto scale setting is not sent to controller when graphics surfaces are used.
2078 // If the surface has been created, perform auto scale with the help of graphics surfaces;
2079 // otherwise, just store the auto scale info.
2080 iGlobalAutoScaleType = aScaleType;
2081 iGlobalHorizPos = aHorizPos;
2082 iGlobalVertPos = aVertPos;
2084 TInt count = iActiveDisplays.Count();
2086 for (TInt i = 0; i < count; ++i)
2088 iActiveDisplays[i]->SetAutoScaleL(aScaleType, aHorizPos, aVertPos, iCropRegion);
2092 User::LeaveIfError(iVideoPlayControllerExtCustomCommands.SetAutoScale(aScaleType, aHorizPos, aVertPos));
2093 #endif // SYMBIAN_BUILD_GCE
2094 DEBUG_PRINTF("CVideoPlayerUtility::CBody::SetAutoScaleL--");
2097 #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT
2098 TBool CVideoPlayerUtility::CBody::SubtitlesAvailable()
2100 if (!iControllerOpen)
2105 return CMMFSubtitleUtility::SubtitlesAvailable(iController);
2108 void CVideoPlayerUtility::CBody::EnableSubtitlesL()
2110 // Check if video file and controller is opened
2111 __ASSERT_ALWAYS(iControllerOpen, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilityFileNotOpened, KErrNotReady));
2112 // Check if subtitles are already enabled
2113 __ASSERT_ALWAYS(!iSubtitleUtility, User::Leave(KErrInUse));
2114 // Check if display window is added
2115 TBool windowsAdded = EFalse;
2116 for (TInt i = iActiveDisplays.Count()-1; (i >= 0 && windowsAdded == EFalse); --i)
2118 CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
2119 windowsAdded = display->HasWindows();
2121 __ASSERT_ALWAYS(windowsAdded, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilityNoWindowAdded, KErrNotReady));
2124 iSubtitleUtility = CMMFSubtitleUtility::NewL(iController, *iWs);
2125 TInt err = iSubtitleUtility->EnableSubtitles();
2126 if (KErrNone != err)
2128 delete iSubtitleUtility;
2129 iSubtitleUtility = NULL;
2130 if (KErrNotSupported == err || KErrNotFound == err)
2132 // controller does not support subtitles or subtitle source not found,
2133 // panic client because they should have called SubtitlesAvailable first
2134 VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotSupported, err);
2137 // leave in release mode or any other error
2141 TBool subtitleEnabled = EFalse;
2142 TInt count = iActiveDisplays.Count();
2144 // add the windows in the orders that they were added
2145 for (TInt i = 0; i < count; ++i)
2147 CMediaClientVideoDisplayBody* display = iActiveDisplays[i];
2148 err = EnableSubtitles(*display);
2150 if (KErrNone == err)
2152 subtitleEnabled = ETrue;
2156 // no subtitle window was enabled successfully, enable subtitle failed
2157 if (!subtitleEnabled)
2159 DisableSubtitles(); // disable subtitle on controller side
2160 User::Leave(err); // Leave with error returned by last EnableSubtitles call
2164 void CVideoPlayerUtility::CBody::DisableSubtitles()
2166 if (iSubtitleUtility)
2168 iSubtitleUtility->DisableSubtitles();
2170 delete iSubtitleUtility;
2171 iSubtitleUtility = NULL;
2175 TArray<TLanguage> CVideoPlayerUtility::CBody::SupportedSubtitleLanguagesL()
2177 // Check if subtitles have been enabled
2178 __ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
2180 return iSubtitleUtility->SupportedSubtitleLanguagesL();
2183 TLanguage CVideoPlayerUtility::CBody::SubtitleLanguageL()
2185 // Check if subtitles have been enabled
2186 __ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
2188 return iSubtitleUtility->SubtitleLanguage();
2191 void CVideoPlayerUtility::CBody::SetSubtitleLanguageL(TLanguage aLanguage)
2193 // Check if subtitles have been enabled
2194 __ASSERT_ALWAYS(iSubtitleUtility, VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleNotEnabled, KErrNotReady));
2196 TInt err = iSubtitleUtility->SetSubtitleLanguage(aLanguage);
2197 if (KErrNotSupported == err)
2199 // panic on debug because client should call SupportedSubtitleLanguagesL() first
2200 VPUDebugPanicOrLeaveL(EMMFVideoPlayerUtilitySubtitleLanguageNotSupported, KErrNotSupported);
2202 User::LeaveIfError(err);
2205 void CVideoPlayerUtility::CBody::RedrawSubtitle(RWindow& aWindow, const TRect &aRect)
2207 if (iSubtitleUtility)
2209 // subtitle is enabled
2210 RWindow* window = FindWindowWithWsHandle(iActiveDisplays, aWindow.WsHandle());
2211 if (window) // check that window was added for video playback
2213 iSubtitleUtility->RedrawSubtitle(aWindow, aRect);
2216 // else ignore the redraw request
2219 RWindow* CVideoPlayerUtility::CBody::FindWindowWithWsHandle(const RPointerArray<CMediaClientVideoDisplayBody>& aDisplays, TInt aWsHandle)
2221 TInt count = aDisplays.Count();
2223 for (TInt i = 0; i < count; ++i)
2225 CMediaClientVideoDisplayBody* display = aDisplays[i];
2226 RArray<CMediaClientVideoDisplayBody::TWindowData>& windows = display->Windows();
2227 TInt pos = windows.Find(aWsHandle, CMediaClientVideoDisplayBody::TWindowData::CompareByWsHandle);
2230 return windows[pos].iWindow2;
2237 void CVideoPlayerUtility::CBody::GetSubtitleConfigFromWindowData(CMediaClientVideoDisplayBody::TWindowData& aWindowData, TMMFSubtitleWindowConfig& aConfig)
2239 aConfig.iWindowId = aWindowData.iWindow->WsHandle();
2240 aConfig.iWindowClipRect = aWindowData.iClipRect;
2241 aConfig.iDisplayMode = aWindowData.iWindow->DisplayMode();
2242 aConfig.iRotation = aWindowData.iRotation;
2245 TInt CVideoPlayerUtility::CBody::EnableSubtitles(CMediaClientVideoDisplayBody& aDisplay)
2247 TBool windowAdded = EFalse;
2248 RArray<CMediaClientVideoDisplayBody::TWindowData> windows = aDisplay.Windows();
2250 TInt count = windows.Count();
2251 TInt err = KErrNone;
2252 // add the windows in the orders that they are added
2253 for (TInt i = 0; i < count; ++i)
2255 err = AddSubtitleConfig(windows[i]);
2256 if (KErrNone == err)
2258 windowAdded = ETrue;
2262 // Return the error code returned by the last AddSubtitleConfig call.
2271 TInt CVideoPlayerUtility::CBody::AddSubtitleConfig(CMediaClientVideoDisplayBody::TWindowData& aWindowData)
2273 ASSERT(iSubtitleUtility);
2274 TMMFSubtitleWindowConfig config;
2275 GetSubtitleConfigFromWindowData(aWindowData, config);
2277 return iSubtitleUtility->AddSubtitleConfig(config);
2279 #endif //SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT