os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmcameraclientsession.cpp
Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include <ecom/ecom.h>
22 #include <ecom/implementationproxy.h>
25 #include "mmcameraclientsession.h"
26 #include "mmdirectviewfinder.h"
28 #include <graphics/surfaceconfiguration.h>
32 * First-phase constructor
34 CMMCameraClientSession::CMMCameraClientSession():iCameraObserver2(NULL),
37 iPrepareCompleted(EFalse),
38 iCollaborativeClient(EFalse)
43 * NewL() factory function
45 CMMCameraClientSession* CMMCameraClientSession::NewL()
47 FileDependencyUtil::CheckFileDependencyL();
48 return new (ELeave) CMMCameraClientSession;
54 CMMCameraClientSession::~CMMCameraClientSession()
56 delete iCameraPowerHandler;
57 delete iCameraAccessHandler;
60 iCameraSession.Close();
69 * Derived from CCameraPlugin. Second Phase contruction
73 void CMMCameraClientSession::Construct2L(MCameraObserver& /*aObserver*/, TInt /*aCameraIndex*/)
75 User::Leave(KErrNotSupported);
79 * Derived from CCameraPlugin. Second Phase contruction for collaborative clients
83 void CMMCameraClientSession::Construct2DupL(MCameraObserver& /*aObserver*/, TInt /*aCameraHandle*/)
85 User::Leave(KErrNotSupported);
89 * Derived from CCameraPlugin. Second Phase contruction
93 void CMMCameraClientSession::Construct2L(MCameraObserver2& aObserver, TInt aCameraIndex, TInt aPriority)
95 if (aCameraIndex > CamerasAvailable())
97 User::Leave(KErrNotSupported);
100 iCameraIndex = aCameraIndex;
101 iPriority = aPriority;
102 iCameraObserver2 = &aObserver;
106 User::LeaveIfError(iCameraSession.Connect());
111 openCam.iCameraIndex = iCameraIndex;
112 openCam.iPriority = iPriority;
113 openCam.iHandle = KECamHandleNotKnown;
114 openCam.iMMCapability = ETrue; //could be changed.
115 openCam.iCollaborativeClient = EFalse;
117 TOpenCameraPckg openCamBuf(openCam);
119 User::LeaveIfError(iCameraSession.SendMessage(ECamOpenCamera, openCamBuf));
120 // since this call is synchronous, providing reference to local
121 // varialbe is not a problem.
123 iCameraAccessHandler = CMMCameraAccessHandler::NewL(this, CActive::EPriorityStandard);
124 iCameraPowerHandler = CMMCameraPowerHandler::NewL(this, CActive::EPriorityStandard);
128 * Derived from CCameraPlugin. Second Phase contruction for collaborative clients
132 void CMMCameraClientSession::Construct2DupL(MCameraObserver2& /*aObserver*/, TInt /*aCameraHandle*/)
134 User::Leave(KErrNotSupported);
139 // from CCamera itself
143 * Retrieves information about the currectly reserved camera device
145 * @see CCamera::CameraInfo()
147 void CMMCameraClientSession::CameraInfo(TCameraInfo& /*aInfo*/) const
153 * Reserves the camera
155 * @see CCamera::Reserve()
157 void CMMCameraClientSession::Reserve()
159 iCameraAccessHandler->Reserve();
163 * Relinquishes control of the camera device
165 * @see CCamera::Release()
167 void CMMCameraClientSession::Release()
169 iCameraSession.SendMessage(ECamCameraAccessControl, ECameraRelease);
174 * Powers on the camera device
176 * @see CCamera::PowerOn()
178 void CMMCameraClientSession::PowerOn()
180 iCameraPowerHandler->PowerOn();
184 * Powers down the camera device
186 * @see CCamera::PowerOff()
188 void CMMCameraClientSession::PowerOff()
190 iCameraSession.SendMessage(ECamPowerCamera, ECameraPowerOff);
195 * Retrieves the handle of the currently reserved camera
197 * @see CCamera::Handle()
199 TInt CMMCameraClientSession::Handle()
201 TCameraHandle handle;
202 TCameraHandlePckg pckg(handle);
204 iCameraSession.SendRxMessage(ECamCameraHandle, pckg);
207 return handle.iHandle;
211 * Sets the optical zoom level
213 * @see CCamera::SetZoomFactorL()
215 void CMMCameraClientSession::SetZoomFactorL(TInt aZoomFactor)
217 User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EZoomFactor, aZoomFactor));
221 * Retrieves current optical zoom level
223 * @see CCamera::ZoomFactor()
225 TInt CMMCameraClientSession::ZoomFactor() const
227 TCameraZoom zoomFactor;
228 TCameraZoomPckg pckg(zoomFactor);
229 iCameraSession.SendRxMessage(ECamGetParameter, EZoomFactor, pckg);
231 return zoomFactor.iZoom;
235 * Sets the digital zoom level
237 * @see CCamera::SetDigitalZoomFactorL()
239 void CMMCameraClientSession::SetDigitalZoomFactorL(TInt aDigitalZoomFactor)
241 User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EDigitalZoomFactor, aDigitalZoomFactor));
245 * Retrieves the current digital zoom level
247 * @see CCamera::DigitalZoomFactor()
249 TInt CMMCameraClientSession::DigitalZoomFactor() const
251 TCameraDigitalZoom digitalZoomFactor;
252 TCameraDigitalZoomPckg pckg(digitalZoomFactor);
253 iCameraSession.SendRxMessage(ECamGetParameter, EDigitalZoomFactor, pckg);
254 digitalZoomFactor = pckg();
255 return digitalZoomFactor.iDigitalZoom;
259 * Sets the contrast level
261 * @see CCamera::SetContrastL()
263 void CMMCameraClientSession::SetContrastL(TInt aContrast)
265 User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EContrast, aContrast));
269 * Retrieves the current contrast level
271 * @see CCamera::Contrast()
273 TInt CMMCameraClientSession::Contrast() const
275 TCameraContrast contrast;
276 TCameraContrastPckg pckg(contrast);
277 iCameraSession.SendRxMessage(ECamGetParameter, EContrast, pckg);
279 return contrast.iContrast;
283 * Sets the brightness level
285 * @see CCamera::SetBrightnessL()
287 void CMMCameraClientSession::SetBrightnessL(TInt aBrightness)
289 User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EBrightness, aBrightness));
293 * Retrieves the current brightness level
295 * @see CCamera::Brigthness()
297 TInt CMMCameraClientSession::Brightness() const
299 TCameraBrightness brightness;
300 TCameraBrightnessPckg pckg(brightness);
301 iCameraSession.SendRxMessage(ECamGetParameter, EBrightness, pckg);
303 return brightness.iBrightness;
307 * Sets the flash level
309 * @see CCamera::SetFlashL()
311 void CMMCameraClientSession::SetFlashL(TFlash aFlash)
314 flash.iFlash = aFlash;
315 TCameraFlashPckg pckg(flash);
317 User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EFlash, pckg));
321 * Retrieves the current flash level
323 * @see CCamera::Flash()
325 CCamera::TFlash CMMCameraClientSession::Flash() const
328 TCameraFlashPckg pckg(flash);
330 iCameraSession.SendRxMessage(ECamGetParameter, EFlash, pckg);
336 * Sets the exposure level
338 * @see CCamera::SetExposureL()
340 void CMMCameraClientSession::SetExposureL(TExposure aExposure)
342 TCameraExposure exposure;
343 exposure.iExposure = aExposure;
344 TCameraExposurePckg pckg(exposure);
346 User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EExposure, pckg));
350 * Retrieves the current exposure level
352 * @see CCamera::Exposure()
354 CCamera::TExposure CMMCameraClientSession::Exposure() const
356 TCameraExposure exposure;
357 TCameraExposurePckg pckg(exposure);
359 iCameraSession.SendRxMessage(ECamGetParameter, EExposure, pckg);
361 return exposure.iExposure;
365 * Sets the white balance level
367 * @see CCamera::SetWhiteBalance()
369 void CMMCameraClientSession::SetWhiteBalanceL(TWhiteBalance aWhiteBalance)
371 TCameraWhiteBalance whiteBalance;
372 whiteBalance.iWhiteBalance = aWhiteBalance;
373 TCameraWhiteBalancePckg pckg(whiteBalance);
375 User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EWhiteBalance, pckg));
379 * Retrieves the current white balance level
381 * @see CCamera::WhiteBalance()
383 CCamera::TWhiteBalance CMMCameraClientSession::WhiteBalance() const
385 TCameraWhiteBalance whiteBalance;
386 TCameraWhiteBalancePckg pckg(whiteBalance);
388 iCameraSession.SendRxMessage(ECamGetParameter, EWhiteBalance, pckg);
389 whiteBalance = pckg();
390 return whiteBalance.iWhiteBalance;
394 * Starts client direct viewfinder.
395 * Not supported in this implementation.
397 * @see CCamera::StartViewFinderDirectL()
399 void CMMCameraClientSession::StartViewFinderDirectL(RWsSession& /*aWs*/, CWsScreenDevice& /*aScreenDevice*/, RWindowBase& /*aWindow*/, TRect& /*aScreenRect*/)
401 User::Leave(KErrNotSupported);
405 * Starts client direct viewfinder.
406 * Not supported in this implementation.
408 * @see CCamera::StartViewFinderDirectL()
410 void CMMCameraClientSession::StartViewFinderDirectL(RWsSession& /*aWs*/, CWsScreenDevice& /*aScreenDevice*/, RWindowBase& /*aWindow*/, TRect& /*aScreenRect*/, TRect& /*aClipRect*/)
412 User::Leave(KErrNotSupported);
416 * Starts client viewfinder.
417 * Not supported in this implementation.
419 * @see CCamera::StartViewFinderBitmapsL()
421 void CMMCameraClientSession::StartViewFinderBitmapsL(TSize& /*aSize*/)
423 User::Leave(KErrNotSupported);
427 * Starts client viewfinder.
428 * Not supported in this implementation.
430 * @see CCamera::StartViewFinderBitmapsL()
432 void CMMCameraClientSession::StartViewFinderBitmapsL(TSize& /*aSize*/, TRect& /*aClipRect*/)
434 User::Leave(KErrNotSupported);
438 * Starts client viewfinder.
439 * Not supported in this implementation.
441 * @see CCamera::StartViewFinderL()
443 void CMMCameraClientSession::StartViewFinderL(CCamera::TFormat /*aImageFormat*/, TSize& /*aSize*/)
445 User::Leave(KErrNotSupported);
449 * Starts client viewfinder.
450 * Not supported in this implementation.
452 * @see CCamera::StartViewFinderL()
454 void CMMCameraClientSession::StartViewFinderL(CCamera::TFormat /*aImageFormat*/, TSize& /*aSize*/, TRect& /*aClipRect*/)
456 User::Leave(KErrNotSupported);
460 * Stops client viewfinder.
461 * Not supported in this implementation.
463 * @see CCamera::StopViewFinder()
465 void CMMCameraClientSession::StopViewFinder()
471 * Queries if viewfinder is active.
472 * Not supported in this implementation.
474 * @see CCamera::ViewFinderActive()
476 TBool CMMCameraClientSession::ViewFinderActive() const
482 * Turns on/off viewfinder mirrorring.
483 * Not supported in this implementation.
485 * @see CCamera::SetViewFinderMirrorL()
487 void CMMCameraClientSession::SetViewFinderMirrorL(TBool /*aMirror*/)
489 User::Leave(KErrNotSupported);
493 * Queries whether viewfinder mirrorring is on or off.
494 * Not supported in this implementation.
496 * @see CCamera::ViewFinderMirrorL()
498 TBool CMMCameraClientSession::ViewFinderMirror() const
504 * Prepares image capture.
506 * @see CCamera::PrepareImageCapture()
508 void CMMCameraClientSession::PrepareImageCaptureL(CCamera::TFormat /*aImageFormat*/, TInt /*aSizeIndex*/)
510 User::Leave(KErrNotSupported);
514 * Prepares image capture.
516 * @see CCamera::PrepareImageCapture()
518 void CMMCameraClientSession::PrepareImageCaptureL(CCamera::TFormat /*aImageFormat*/, TInt /*aSizeIndex*/, const TRect& /*aClipRect*/)
520 User::Leave(KErrNotSupported);
526 * @see CCamera::CaptureImage()
528 void CMMCameraClientSession::CaptureImage()
534 * Cancels any ongoing image capture.
536 * @see CCamera::CaptureImage()
538 void CMMCameraClientSession::CancelCaptureImage()
544 * Enumerates image capture sizes.
546 * @see CCamera::EnumerateCaptureSizes()
548 void CMMCameraClientSession::EnumerateCaptureSizes(TSize& /*aSize*/, TInt /*aSizeIndex*/, CCamera::TFormat /*aFormat*/) const
554 * Prepares video capture.
556 * @see CCamera::PrepareVideoCaptureL()
558 void CMMCameraClientSession::PrepareVideoCaptureL(CCamera::TFormat /*aFormat*/, TInt /*aSizeIndex*/, TInt /*aRateIndex*/, TInt /*aBuffersToUse*/, TInt /*aFramesPerBuffer*/)
560 User::Leave(KErrNotSupported);
564 * Prepares video capture.
566 * @see CCamera::PrepareVideoCaptureL()
568 void CMMCameraClientSession::PrepareVideoCaptureL(CCamera::TFormat /*aFormat*/, TInt /*aSizeIndex*/, TInt /*aRateIndex*/, TInt /*aBuffersToUse*/, TInt /*aFramesPerBuffer*/, const TRect& /*aClipRect*/)
570 User::Leave(KErrNotSupported);
574 * Starts video capture.
576 * @see CCamera::StartVideoCapture()
578 void CMMCameraClientSession::StartVideoCapture()
584 * Stops video capture.
586 * @see CCamera::StopVideoCapture()
588 void CMMCameraClientSession::StopVideoCapture()
594 * Queries whether video capture is active.
596 * @see CCamera::VideoCaptureActive()
598 TBool CMMCameraClientSession::VideoCaptureActive() const
604 * Enumerates video frame sizes.
606 * @see CCamera::EnumerateVideoFrameSizes()
608 void CMMCameraClientSession::EnumerateVideoFrameSizes(TSize& /*aSize*/, TInt /*aSizeIndex*/, CCamera::TFormat /*aFormat*/) const
614 * Enumerates video frame rates.
616 * @see CCamera::EnumerateVideoFrameRates()
618 void CMMCameraClientSession::EnumerateVideoFrameRates(TReal32& /*aRate*/, TInt /*aRateIndex*/, CCamera::TFormat /*aFormat*/, TInt /*aSizeIndex*/, TExposure /*aExposure*/) const
624 * Retrieve the frame size.
626 * @see CCamera::GetFrameSize()
628 void CMMCameraClientSession::GetFrameSize(TSize& /*aSize*/) const
634 * Retrieve the frame rate.
636 * @see CCamera::FrameRate()
638 TReal32 CMMCameraClientSession::FrameRate() const
640 return static_cast<TReal32>(0);
644 * Retrieve the number of buffers currently in use.
646 * @see CCamera::BuffersInUse()
648 TInt CMMCameraClientSession::BuffersInUse() const
654 * Retrieve the number of frames per buffer.
656 * @see CCamera::FramesPerBuffer()
658 TInt CMMCameraClientSession::FramesPerBuffer() const
664 * Set the Jpeg quality.
666 * @see CCamera::SetJpegQuality()
668 void CMMCameraClientSession::SetJpegQuality(TInt /*aQuality*/)
674 * Retrieve the Jpeg quality.
676 * @see CCamera::JpegQuality()
678 TInt CMMCameraClientSession::JpegQuality() const
684 * Retrieves a custom interface based on the id passed in by the client.
686 * @see CCamera::CustomInterface()
688 TAny* CMMCameraClientSession::CustomInterface(TUid aInterface)
690 switch (aInterface.iUid)
692 // The framework retrieves KECamMCameraV2DirectViewFinderUidValue followed by KECamMCameraBaseV2DirectViewFinderUidValue
693 // We take care to initialise iDirectViewFinder in the first case and use it in the subsequent call
694 case KECamMCameraV2DirectViewFinderUidValue:
696 ASSERT(!iDirectViewFinder);
697 TRAPD(err, iDirectViewFinder = CMMDirectViewFinder::NewL(*this));
703 return static_cast<MCameraV2DirectViewFinder*>(iDirectViewFinder);
706 case KECamMCameraBaseV2DirectViewFinderUidValue:
708 ASSERT(iDirectViewFinder);
709 iVF = static_cast<MCameraViewFinder*>(iDirectViewFinder);
710 //delete iDirectViewFinder;
711 iDirectViewFinder = NULL;
723 // From CCameraInfoPlugin
725 CMMCameraClientSessionInfo* CMMCameraClientSessionInfo::NewL()
727 FileDependencyUtil::CheckFileDependencyL();
728 return new (ELeave) CMMCameraClientSessionInfo;
731 CMMCameraClientSessionInfo::~CMMCameraClientSessionInfo()
736 * Retrieves the number of cameras available.
738 * @see CCameraInfoPlugin::CamerasAvailable()
740 TInt CMMCameraClientSessionInfo::CamerasAvailable()
742 // One-off connection to the server
743 RMMCameraSession cameraSession;
744 TInt error = cameraSession.Connect();
745 if (error != KErrNone)
750 TCamerasAvailable info;
751 TCamerasAvailablePckg pckg(info);
753 error = cameraSession.SendMessage(ECamQueryCamerasAvailable, pckg);
754 cameraSession.Close();
755 if (error != KErrNone)
761 return info.iCameraCount;
764 CMMCameraClientSessionInfo::CMMCameraClientSessionInfo()
770 void FileDependencyUtil::CheckFileDependencyL()
774 CleanupClosePushL(fsSession);
775 User::LeaveIfError(fsSession.Connect());
776 TInt err = file.Open(fsSession, KMMCameraPluginName, EFileRead);
780 User::LeaveIfError(KErrNotSupported);
782 CleanupStack::PopAndDestroy(&fsSession);
787 // CLASS CMMCameraAccessHandler
790 CMMCameraAccessHandler::CMMCameraAccessHandler(CMMCameraClientSession* aPlugin, TInt aPriority): CActive(aPriority),
795 CMMCameraAccessHandler* CMMCameraAccessHandler::NewL(CMMCameraClientSession* aPlugin, TInt aPriority)
797 CMMCameraAccessHandler* self = new (ELeave) CMMCameraAccessHandler(aPlugin, aPriority);
798 CActiveScheduler::Add(self);
802 CMMCameraAccessHandler::~CMMCameraAccessHandler()
807 void CMMCameraAccessHandler::Reserve()
811 // Reserve the camera
812 iPlugin->iCameraSession.ReceiveMessage(ECamCameraAccessControl, ECameraReservedNotification, iStatus);
817 // Reserve has been called again before first call has completed so notify the client
818 TECAMEvent ecamEvent(KUidECamEventReserveComplete, KErrInUse);
819 iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
823 void CMMCameraAccessHandler::RunL()
825 TInt ret = iStatus.Int();
827 if(!iPlugin->iReserved)
831 iPlugin->iReserved = ETrue;
834 // Continue monitoring for overthrow messages should a higher priority client reserve the same camera index
835 iPlugin->iCameraSession.ReceiveMessage(ECamCameraAccessControl, ECameraOverthrowNotification, iStatus);
840 // notify the client that reserve has completed, successfully or otherwise
841 TECAMEvent ecamEvent(KUidECamEventReserveComplete, ret);
842 iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
846 iPlugin->iReserved = EFalse;
850 // Client has been overthrown by a second client with higher priority
851 TECAMEvent ecamEvent(KUidECamEventCameraNoLongerReserved, ret);
852 iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
857 void CMMCameraAccessHandler::DoCancel()
859 if(!iPlugin->iReserved)
861 iPlugin->iCameraSession.SendMessage(ECamCameraAccessControl, ECameraCancelReservedNotification);
863 // Notify client that ongoing reserve request was cancelled
864 TECAMEvent ecamEvent(KUidECamEventReserveComplete, KErrCancel);
865 iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
869 iPlugin->iCameraSession.SendMessage(ECamCameraAccessControl, ECameraCancelOverthrowNotification);
870 iPlugin->iReserved = EFalse;
877 // CLASS CMMCameraPowerHandler
880 CMMCameraPowerHandler::CMMCameraPowerHandler(CMMCameraClientSession* aPlugin, TInt aPriority): CActive(aPriority),
885 CMMCameraPowerHandler* CMMCameraPowerHandler::NewL(CMMCameraClientSession* aPlugin, TInt aPriority)
887 CMMCameraPowerHandler* self = new (ELeave) CMMCameraPowerHandler(aPlugin, aPriority);
888 CActiveScheduler::Add(self);
892 CMMCameraPowerHandler::~CMMCameraPowerHandler()
897 void CMMCameraPowerHandler::PowerOn()
901 iPlugin->iCameraSession.ReceiveMessage(ECamPowerCamera, ECameraPowerOnNotification, iStatus);
906 // PowerOn has been called again before first call has completed so notify the client
907 TECAMEvent ecamEvent(KUidECamEventPowerOnComplete, KErrAlreadyExists);
908 iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
912 void CMMCameraPowerHandler::RunL()
914 TInt ret = iStatus.Int();
916 if(!iPlugin->iPoweredUp)
920 iPlugin->iPoweredUp = ETrue;
924 TECAMEvent ecamEvent(KUidECamEventPowerOnComplete, ret);
925 iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
928 void CMMCameraPowerHandler::DoCancel()
930 if(!iPlugin->iPoweredUp)
932 iPlugin->iCameraSession.SendMessage(ECamPowerCamera, ECameraCancelPowerOnNotification);
937 // __________________________________________________________________________
938 // Exported proxy for instantiation method resolution
939 // Define the interface UIDs
940 const TImplementationProxy ImplementationTable[] =
942 IMPLEMENTATION_PROXY_ENTRY(KUidMMCameraClientSession, CMMCameraClientSession::NewL),
943 IMPLEMENTATION_PROXY_ENTRY(KUidMMCameraClientSessionInfo, CMMCameraClientSessionInfo::NewL)
946 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
948 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
950 return ImplementationTable;