os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraservercontroller.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 "mmcameraserver.h"
22 #include "mmcameraserversession.h"
23 #include "mmcameraservercontroller.h"
25 #include <graphics/surfacemanager.h>
27 using namespace MMClient;
28 using namespace MMVideoComponents;
29 using namespace MMCameraComponents;
31 static const TInt KMMCamHandleNumberBase = 500;
32 const TInt KDefaultFrameRate = 30;
34 CMMCameraServerController* CMMCameraServerController::NewL(TInt aCameraIndex)
36 CMMCameraServerController* self = new(ELeave) CMMCameraServerController(aCameraIndex);
37 CleanupStack::PushL(self);
39 CleanupStack::Pop(self);
43 CMMCameraServerController::CMMCameraServerController(TInt aCameraIndex): iCameraIndex(aCameraIndex),
44 iCameraHandle(KMMCamHandleNumberBase + iCameraIndex),
45 iMMCapability(EFalse),
46 iViewFinderState(CCamera::CCameraV2DirectViewFinder::EViewFinderInActive),
47 iFlash(CCamera::EFlashNone),
48 iExposure(CCamera::EExposureAuto),
49 iWhiteBalance(CCamera::EWBAuto)
53 void CMMCameraServerController::ConstructL()
55 User::LeaveIfError(iMMServer.Connect()); // Connect to the MM server
57 // Create characterizations for camera and graphics sink
58 XMMCameraViewFinderCharacterization* cameraViewFinderChar = XMMCameraViewFinderCharacterization::New();
59 XMMVideoGraphicsSinkCharacterization* graphicsSinkChar = XMMVideoGraphicsSinkCharacterization::New();
60 XMMCameraSensorCharacterization* cameraSensorChar = XMMCameraSensorCharacterization::New();
61 // XMMCameraCaptureCharacterization* cameraCaptureChar = XMMCameraCaptureCharacterization::New();
63 // Open stream, stream container and camera/graphics sink components
64 User::LeaveIfError(iMMStreamContainer.Open());
65 User::LeaveIfError(iMMStream.Open(iMMStreamContainer));
67 User::LeaveIfError(iCameraViewFinder.Open(*cameraViewFinderChar));
68 User::LeaveIfError(iMMStream.Append(iCameraViewFinder));
70 User::LeaveIfError(iGraphicsSink.Open(*graphicsSinkChar));
71 User::LeaveIfError(iMMStream.Append(iGraphicsSink));
73 User::LeaveIfError(iCameraSensor.Open(*cameraSensorChar));
74 User::LeaveIfError(iMMStream.Append(iCameraSensor));
77 CMMCameraServerController::~CMMCameraServerController()
79 iCameraCapture.Close();
80 iCameraSensor.Close();
81 iGraphicsSink.Close();
82 iCameraViewFinder.Close();
84 iMMStreamContainer.Close();
87 iCamCntrlLink.Deque();
88 iCamCntrlLink.iNext = NULL;
91 TInt CMMCameraServerController::CameraIndex() const
96 TInt CMMCameraServerController::CameraHandle() const
101 void CMMCameraServerController::PrepareDirectViewFinderL(TDirectViewFinderInfo& aDirectViewFinderInfo)
103 // Default mode - One Shot setting off
104 User::LeaveIfError(iCameraSensor.SetSensorOneShot(EFalse));
106 User::LeaveIfError(iCameraViewFinder.SetFrameDimensions(aDirectViewFinderInfo.iScreenRect.Width(), aDirectViewFinderInfo.iScreenRect.Height()));
107 User::LeaveIfError(iCameraViewFinder.SetColorFormat(MMCameraComponents::EColorFormatYUV422Planar));
108 // TODO: Replace 2 with calculation to find bytes per pixel depending on color format
109 User::LeaveIfError(iCameraViewFinder.SetStride(aDirectViewFinderInfo.iScreenRect.Width() * 2));
110 // Default mode - Frame rate = 30 fps
111 User::LeaveIfError(iCameraViewFinder.SetFrameRate(KDefaultFrameRate));
113 User::LeaveIfError(iMMServer.Commit(iMMStreamContainer));
115 // User::LeaveIfError(iGraphicsSink.SetScreenNumber(aDirectViewFinderInfo.iScreenNum)); // Commented out as not yet supported by translators
116 User::LeaveIfError(iGraphicsSink.GetSurfaceId(aDirectViewFinderInfo.iSurfaceId));
117 iClipRect = aDirectViewFinderInfo.iClipRect;
120 TInt CMMCameraServerController::StartDirectViewFinder()
122 TRequestStatus status;
123 iMMStream.Start(status);
124 User::WaitForRequest(status);
125 if(status.Int() == KErrNone)
127 iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderActive;
133 void CMMCameraServerController::StopDirectViewFinder()
135 TRequestStatus status;
136 iMMStream.Stop(status);
137 User::WaitForRequest(status);
138 iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderInActive;
141 void CMMCameraServerController::PauseDirectViewFinder()
143 TRequestStatus status;
144 iMMStream.Pause(status);
145 User::WaitForRequest(status);
146 iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderPause;
149 void CMMCameraServerController::ResumeDirectViewFinder()
151 TRequestStatus status;
152 iMMStream.Resume(status);
153 User::WaitForRequest(status);
154 iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderActive;
157 CCamera::CCameraV2DirectViewFinder::TViewFinderState CMMCameraServerController::GetDirectViewFinderState() const
159 return iViewFinderState;
162 TInt CMMCameraServerController::SetDirectViewFinderMirror(const TBool aMirror)
164 // mismatch here between ECAM API (which only specify whether mirror is on or off)
165 // and RMMCameraSensor (which specify horizontal and/or vertical mirror modes)
168 return iCameraSensor.SetMirrorType(EMirrorHorizontal);
172 return iCameraSensor.SetMirrorType(EMirrorNone);
176 TInt CMMCameraServerController::GetDirectViewFinderMirror(TBool& aMirror)
178 // mismatch here between ECAM API (which only specify whether mirror is on or off)
179 // and RMMCameraSensor (which specify horizontal and/or vertical mirror modes)
181 TInt error = iCameraSensor.GetMirrorType(mirror);
182 if (error != KErrNone)
187 if (mirror == EMirrorHorizontal)
199 TInt CMMCameraServerController::DirectViewFinderProperties(TInt& aScreenNum, TRect& aScreenRect, TRect& aClipRect)
201 TUint screenNumber = 0;
202 TInt error = iGraphicsSink.GetScreenNumber(screenNumber); // will currently just return 0 as screen number Set() not yet supported
203 if (error == KErrNone)
205 aScreenNum = screenNumber;
208 TInt error = iCameraViewFinder.GetFrameDimensions(width, height);
209 if (error ==KErrNone)
211 aScreenRect.SetWidth(width);
212 aScreenRect.SetHeight(height);
213 aClipRect = iClipRect;
225 TInt CMMCameraServerController::SetZoom(const TInt aZoom)
231 TInt CMMCameraServerController::SetDigitalZoom(const TInt aDigitalZoom)
233 iDigitalZoom = aDigitalZoom;
237 TInt CMMCameraServerController::SetContrast(const TInt aContrast)
239 iContrast = aContrast;
243 TInt CMMCameraServerController::SetBrightness(const TInt aBrightness)
245 iBrightness = aBrightness;
247 // return iCameraSensor.SetBrightness(aBrightness);
250 TInt CMMCameraServerController::SetFlash(const CCamera::TFlash aFlash)
256 TInt CMMCameraServerController::SetExposure(const CCamera::TExposure aExposure)
258 iExposure = aExposure;
262 // Several CCamera exposure values dont have equivalent TMMExposureControl values
265 case CCamera::EExposureAuto:
267 return iCameraSensor.SetExposureControl(EExposureControlAuto);
269 case CCamera::EExposureNight:
271 return iCameraSensor.SetExposureControl(EExposureControlNight);
273 case CCamera::EExposureBacklight:
275 return iCameraSensor.SetExposureControl(EExposureControlBackLight);
277 case CCamera::EExposureCenter:
279 return iCameraSensor.SetExposureControl(EExposureControlSpotLight);
281 case CCamera::EExposureSport:
283 return iCameraSensor.SetExposureControl(EExposureControlSports);
285 case CCamera::EExposureSnow:
287 return iCameraSensor.SetExposureControl(EExposureControlSnow);
289 case CCamera::EExposureBeach:
291 return iCameraSensor.SetExposureControl(EExposureControlBeach);
295 return KErrNotSupported;
300 TInt CMMCameraServerController::SetWhiteBalance(const CCamera::TWhiteBalance aWhiteBalance)
302 iWhiteBalance = aWhiteBalance;
305 /* // Several CCamera white balance values dont have equivalent TMMWhiteBalControl values
306 switch (aWhiteBalance)
308 case CCamera::EWBAuto:
310 return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlAuto);
312 case CCamera::EWBDaylight:
314 return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlSunLight);
316 case CCamera::EWBCloudy:
318 return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlCloudy);
320 case CCamera::EWBTungsten:
322 return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlTungsten);
324 case CCamera::EWBFluorescent:
326 return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlFluorescent);
328 case CCamera::EWBFlash:
330 return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlFlash);
332 case CCamera::EWBShade:
334 return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlShade);
336 case CCamera::EWBHorizon:
338 return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlHorizon);
342 return KErrNotSupported;
347 TInt CMMCameraServerController::GetZoom(TInt& aZoom)
353 TInt CMMCameraServerController::GetDigitalZoom(TInt& aDigitalZoom)
355 aDigitalZoom = iDigitalZoom;
359 TInt CMMCameraServerController::GetContrast(TInt& aContrast)
361 aContrast = iContrast;
365 TInt CMMCameraServerController::GetBrightness(TInt& aBrightness)
367 aBrightness = iBrightness;
369 // return iCameraSensor.GetBrightness(aBrightness);
372 TInt CMMCameraServerController::GetFlash(CCamera::TFlash& aFlash)
378 TInt CMMCameraServerController::GetExposure(CCamera::TExposure& aExposure)
380 aExposure = iExposure;
384 // Several CCamera exposure values dont have equivalent TMMExposureControl values
385 TMMExposureControl exposure;
386 TInt error = iCameraSensor.GetExposureControl(exposure);
387 if (error != KErrNone)
394 case EExposureControlAuto:
396 aExposure = CCamera::EExposureAuto;
399 case EExposureControlNight:
401 aExposure = CCamera::EExposureNight;
404 case EExposureControlBackLight:
406 aExposure = CCamera::EExposureBacklight;
409 case EExposureControlSpotLight:
411 aExposure = CCamera::EExposureCenter;
414 case EExposureControlSports:
416 aExposure = CCamera::EExposureSport;
419 case EExposureControlSnow:
421 aExposure = CCamera::EExposureSnow;
424 case EExposureControlBeach:
426 aExposure = CCamera::EExposureBeach;
431 return KErrNotSupported;
438 TInt CMMCameraServerController::GetWhiteBalance(CCamera::TWhiteBalance& aWhiteBalance)
440 aWhiteBalance = iWhiteBalance;
444 // Several CCamera white balance values dont have equivalent TMMWhiteBalControl values
445 TMMWhiteBalControl whiteBal;
446 TInt error = iCameraSensor.GetWhiteBalanceControl(whiteBal);
447 if (error != KErrNone)
452 switch (aWhiteBalance)
454 case EWhiteBalControlAuto:
456 aWhiteBalance = CCamera::EWBAuto;
459 case EWhiteBalControlSunLight:
461 aWhiteBalance = CCamera::EWBDaylight;
464 case EWhiteBalControlCloudy:
466 aWhiteBalance = CCamera::EWBCloudy;
469 case EWhiteBalControlTungsten:
471 aWhiteBalance = CCamera::EWBTungsten;
474 case EWhiteBalControlFluorescent:
476 aWhiteBalance = CCamera::EWBFluorescent;
479 case EWhiteBalControlFlash:
481 aWhiteBalance = CCamera::EWBFlash;
484 case EWhiteBalControlShade:
486 aWhiteBalance = CCamera::EWBShade;
489 case EWhiteBalControlHorizon:
491 aWhiteBalance = CCamera::EWBHorizon;
496 return KErrNotSupported;
503 void CMMCameraServerController::Reset()
505 if (iViewFinderState == CCamera::CCameraV2DirectViewFinder::EViewFinderActive)
507 StopDirectViewFinder();
514 CMMCameraServerControllerQuery* CMMCameraServerControllerQuery::NewL()
516 CMMCameraServerControllerQuery* self = new (ELeave) CMMCameraServerControllerQuery();
517 CleanupStack::PushL(self);
519 CleanupStack::Pop(self);
523 CMMCameraServerControllerQuery::~CMMCameraServerControllerQuery()
528 void CMMCameraServerControllerQuery::ConstructL()
530 User::LeaveIfError(iServer.Connect());
533 CMMCameraServerControllerQuery::CMMCameraServerControllerQuery()
537 TInt CMMCameraServerControllerQuery::GetCamerasAvailable()
539 // Code to query MM server TBC