os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraservercontroller.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraservercontroller.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,541 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @internalComponent
    1.22 +*/
    1.23 +
    1.24 +#include "mmcameraserver.h"
    1.25 +#include "mmcameraserversession.h"
    1.26 +#include "mmcameraservercontroller.h"
    1.27 +
    1.28 +#include <graphics/surfacemanager.h>
    1.29 +
    1.30 +using namespace MMClient;
    1.31 +using namespace MMVideoComponents;
    1.32 +using namespace MMCameraComponents;
    1.33 +
    1.34 +static const TInt KMMCamHandleNumberBase = 500;
    1.35 +const TInt KDefaultFrameRate = 30;
    1.36 +
    1.37 +CMMCameraServerController* CMMCameraServerController::NewL(TInt aCameraIndex)
    1.38 +	{
    1.39 +	CMMCameraServerController* self = new(ELeave) CMMCameraServerController(aCameraIndex);
    1.40 +	CleanupStack::PushL(self);
    1.41 +	self->ConstructL();
    1.42 +	CleanupStack::Pop(self);
    1.43 +	return self;	
    1.44 +	}
    1.45 +
    1.46 +CMMCameraServerController::CMMCameraServerController(TInt aCameraIndex): iCameraIndex(aCameraIndex),
    1.47 +																	 iCameraHandle(KMMCamHandleNumberBase + iCameraIndex),
    1.48 +																	 iMMCapability(EFalse),
    1.49 +																	 iViewFinderState(CCamera::CCameraV2DirectViewFinder::EViewFinderInActive),
    1.50 +																	 iFlash(CCamera::EFlashNone),
    1.51 +																	 iExposure(CCamera::EExposureAuto),
    1.52 +																	 iWhiteBalance(CCamera::EWBAuto)
    1.53 +	{
    1.54 +	}
    1.55 +
    1.56 +void CMMCameraServerController::ConstructL()
    1.57 +	{	
    1.58 +	User::LeaveIfError(iMMServer.Connect()); // Connect to the MM server
    1.59 +
    1.60 +	// Create characterizations for camera and graphics sink
    1.61 +	XMMCameraViewFinderCharacterization* cameraViewFinderChar = XMMCameraViewFinderCharacterization::New();
    1.62 +	XMMVideoGraphicsSinkCharacterization* graphicsSinkChar = XMMVideoGraphicsSinkCharacterization::New();
    1.63 +	XMMCameraSensorCharacterization* cameraSensorChar = XMMCameraSensorCharacterization::New();
    1.64 +//	XMMCameraCaptureCharacterization* cameraCaptureChar = XMMCameraCaptureCharacterization::New();
    1.65 +
    1.66 +	// Open stream, stream container and camera/graphics sink components
    1.67 +	User::LeaveIfError(iMMStreamContainer.Open());
    1.68 +	User::LeaveIfError(iMMStream.Open(iMMStreamContainer));
    1.69 +
    1.70 +	User::LeaveIfError(iCameraViewFinder.Open(*cameraViewFinderChar));
    1.71 +	User::LeaveIfError(iMMStream.Append(iCameraViewFinder));
    1.72 +
    1.73 +	User::LeaveIfError(iGraphicsSink.Open(*graphicsSinkChar));
    1.74 +	User::LeaveIfError(iMMStream.Append(iGraphicsSink));
    1.75 +
    1.76 +	User::LeaveIfError(iCameraSensor.Open(*cameraSensorChar));
    1.77 +	User::LeaveIfError(iMMStream.Append(iCameraSensor));
    1.78 +	}
    1.79 +
    1.80 +CMMCameraServerController::~CMMCameraServerController()
    1.81 +	{
    1.82 +	iCameraCapture.Close();
    1.83 +	iCameraSensor.Close();
    1.84 +	iGraphicsSink.Close();
    1.85 +	iCameraViewFinder.Close();
    1.86 +	iMMStream.Close();
    1.87 +	iMMStreamContainer.Close();
    1.88 +	iMMServer.Close();
    1.89 +
    1.90 +	iCamCntrlLink.Deque();
    1.91 +	iCamCntrlLink.iNext = NULL;
    1.92 +	}
    1.93 +
    1.94 +TInt CMMCameraServerController::CameraIndex() const
    1.95 +	{
    1.96 +	return iCameraIndex;
    1.97 +	}
    1.98 +
    1.99 +TInt CMMCameraServerController::CameraHandle() const
   1.100 +	{
   1.101 +	return iCameraHandle;
   1.102 +	}
   1.103 +
   1.104 +void CMMCameraServerController::PrepareDirectViewFinderL(TDirectViewFinderInfo& aDirectViewFinderInfo)
   1.105 +	{
   1.106 +	// Default mode - One Shot setting off
   1.107 +	User::LeaveIfError(iCameraSensor.SetSensorOneShot(EFalse));
   1.108 +
   1.109 +	User::LeaveIfError(iCameraViewFinder.SetFrameDimensions(aDirectViewFinderInfo.iScreenRect.Width(), aDirectViewFinderInfo.iScreenRect.Height()));
   1.110 +	User::LeaveIfError(iCameraViewFinder.SetColorFormat(MMCameraComponents::EColorFormatYUV422Planar));
   1.111 +	// TODO: Replace 2 with calculation to find bytes per pixel depending on color format
   1.112 +	User::LeaveIfError(iCameraViewFinder.SetStride(aDirectViewFinderInfo.iScreenRect.Width() * 2));
   1.113 +	// Default mode - Frame rate = 30 fps
   1.114 +	User::LeaveIfError(iCameraViewFinder.SetFrameRate(KDefaultFrameRate));
   1.115 +
   1.116 +	User::LeaveIfError(iMMServer.Commit(iMMStreamContainer));
   1.117 +
   1.118 +//	User::LeaveIfError(iGraphicsSink.SetScreenNumber(aDirectViewFinderInfo.iScreenNum)); // Commented out as not yet supported by translators
   1.119 +	User::LeaveIfError(iGraphicsSink.GetSurfaceId(aDirectViewFinderInfo.iSurfaceId));
   1.120 +	iClipRect = aDirectViewFinderInfo.iClipRect;
   1.121 +	}
   1.122 +
   1.123 +TInt CMMCameraServerController::StartDirectViewFinder()
   1.124 +	{
   1.125 +	TRequestStatus status;
   1.126 +	iMMStream.Start(status);
   1.127 +	User::WaitForRequest(status);
   1.128 +	if(status.Int() == KErrNone)
   1.129 +		{
   1.130 +		iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderActive;
   1.131 +		}
   1.132 +
   1.133 +	return status.Int();
   1.134 +	}
   1.135 +
   1.136 +void CMMCameraServerController::StopDirectViewFinder()
   1.137 +	{
   1.138 +	TRequestStatus status;
   1.139 +	iMMStream.Stop(status);
   1.140 +	User::WaitForRequest(status);
   1.141 +	iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderInActive;
   1.142 +	}
   1.143 +
   1.144 +void CMMCameraServerController::PauseDirectViewFinder()
   1.145 +	{
   1.146 +	TRequestStatus status;
   1.147 +	iMMStream.Pause(status);
   1.148 +	User::WaitForRequest(status);
   1.149 +	iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderPause;
   1.150 +	}
   1.151 +
   1.152 +void CMMCameraServerController::ResumeDirectViewFinder()
   1.153 +	{
   1.154 +	TRequestStatus status;
   1.155 +	iMMStream.Resume(status);
   1.156 +	User::WaitForRequest(status);
   1.157 +	iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderActive;
   1.158 +	}
   1.159 +
   1.160 +CCamera::CCameraV2DirectViewFinder::TViewFinderState CMMCameraServerController::GetDirectViewFinderState() const
   1.161 +	{
   1.162 +	return iViewFinderState;
   1.163 +	}
   1.164 +
   1.165 +TInt CMMCameraServerController::SetDirectViewFinderMirror(const TBool aMirror)
   1.166 +	{
   1.167 +	// mismatch here between ECAM API (which only specify whether mirror is on or off)
   1.168 +	// and RMMCameraSensor (which specify horizontal and/or vertical mirror modes)
   1.169 +	if (aMirror)
   1.170 +		{
   1.171 +		return iCameraSensor.SetMirrorType(EMirrorHorizontal);
   1.172 +		}
   1.173 +	else
   1.174 +		{
   1.175 +		return iCameraSensor.SetMirrorType(EMirrorNone);
   1.176 +		}
   1.177 +	}
   1.178 +
   1.179 +TInt CMMCameraServerController::GetDirectViewFinderMirror(TBool& aMirror)
   1.180 +	{
   1.181 +	// mismatch here between ECAM API (which only specify whether mirror is on or off)
   1.182 +	// and RMMCameraSensor (which specify horizontal and/or vertical mirror modes)
   1.183 +	TMMMirror mirror;
   1.184 +	TInt error = iCameraSensor.GetMirrorType(mirror);
   1.185 +	if (error != KErrNone)
   1.186 +		{
   1.187 +		return error;
   1.188 +		}
   1.189 +
   1.190 +	if (mirror == EMirrorHorizontal)
   1.191 +		{
   1.192 +		aMirror = ETrue;
   1.193 +		}
   1.194 +	else
   1.195 +		{
   1.196 +		aMirror = EFalse;
   1.197 +		}
   1.198 +
   1.199 +	return KErrNone;
   1.200 +	}
   1.201 +
   1.202 +TInt CMMCameraServerController::DirectViewFinderProperties(TInt& aScreenNum, TRect& aScreenRect, TRect& aClipRect)
   1.203 +	{
   1.204 +	TUint screenNumber = 0;
   1.205 +	TInt error = iGraphicsSink.GetScreenNumber(screenNumber); // will currently just return 0 as screen number Set() not yet supported
   1.206 +	if (error == KErrNone)
   1.207 +		{
   1.208 +		aScreenNum = screenNumber;
   1.209 +		TUint width;
   1.210 +		TUint height;
   1.211 +		TInt error = iCameraViewFinder.GetFrameDimensions(width, height);
   1.212 +		if (error ==KErrNone)
   1.213 +			{
   1.214 +			aScreenRect.SetWidth(width);
   1.215 +			aScreenRect.SetHeight(height);
   1.216 +			aClipRect = iClipRect;
   1.217 +			return KErrNone;
   1.218 +			}
   1.219 +		}
   1.220 +	else
   1.221 +		{
   1.222 +		aScreenNum = -1;
   1.223 +		}
   1.224 +
   1.225 +	return error;	
   1.226 +	}
   1.227 +
   1.228 +TInt CMMCameraServerController::SetZoom(const TInt aZoom)
   1.229 +	{
   1.230 +	iZoom = aZoom;
   1.231 +	return KErrNone;
   1.232 +	}
   1.233 +
   1.234 +TInt CMMCameraServerController::SetDigitalZoom(const TInt aDigitalZoom)
   1.235 +	{
   1.236 +	iDigitalZoom = aDigitalZoom;
   1.237 +	return KErrNone;
   1.238 +	}
   1.239 +
   1.240 +TInt CMMCameraServerController::SetContrast(const TInt aContrast)
   1.241 +	{
   1.242 +	iContrast = aContrast;
   1.243 +	return KErrNone;
   1.244 +	}
   1.245 +
   1.246 +TInt CMMCameraServerController::SetBrightness(const TInt aBrightness)
   1.247 +	{
   1.248 +	iBrightness = aBrightness;
   1.249 +	return KErrNone;
   1.250 +//	return iCameraSensor.SetBrightness(aBrightness);
   1.251 +	}
   1.252 +
   1.253 +TInt CMMCameraServerController::SetFlash(const CCamera::TFlash aFlash)
   1.254 +	{
   1.255 +	iFlash = aFlash;
   1.256 +	return KErrNone;
   1.257 +	}
   1.258 +
   1.259 +TInt CMMCameraServerController::SetExposure(const CCamera::TExposure aExposure)
   1.260 +	{
   1.261 +	iExposure = aExposure;
   1.262 +	return KErrNone;
   1.263 +
   1.264 +	/*
   1.265 +	// Several CCamera exposure values dont have equivalent TMMExposureControl values
   1.266 +	switch (aExposure)
   1.267 +		{
   1.268 +		case CCamera::EExposureAuto:
   1.269 +			{
   1.270 +			return iCameraSensor.SetExposureControl(EExposureControlAuto);
   1.271 +			}
   1.272 +		case CCamera::EExposureNight:
   1.273 +			{
   1.274 +			return iCameraSensor.SetExposureControl(EExposureControlNight);
   1.275 +			}
   1.276 +		case CCamera::EExposureBacklight:
   1.277 +			{
   1.278 +			return iCameraSensor.SetExposureControl(EExposureControlBackLight);
   1.279 +			}
   1.280 +		case CCamera::EExposureCenter:
   1.281 +			{
   1.282 +			return iCameraSensor.SetExposureControl(EExposureControlSpotLight);
   1.283 +			}
   1.284 +		case CCamera::EExposureSport:
   1.285 +			{
   1.286 +			return iCameraSensor.SetExposureControl(EExposureControlSports);
   1.287 +			}
   1.288 +		case CCamera::EExposureSnow:
   1.289 +			{
   1.290 +			return iCameraSensor.SetExposureControl(EExposureControlSnow);
   1.291 +			}
   1.292 +		case CCamera::EExposureBeach:
   1.293 +			{
   1.294 +			return iCameraSensor.SetExposureControl(EExposureControlBeach);
   1.295 +			}
   1.296 +		default:
   1.297 +			{
   1.298 +			return KErrNotSupported;
   1.299 +			}
   1.300 +		}
   1.301 +*/	}
   1.302 +
   1.303 +TInt CMMCameraServerController::SetWhiteBalance(const CCamera::TWhiteBalance aWhiteBalance)
   1.304 +	{
   1.305 +	iWhiteBalance = aWhiteBalance;
   1.306 +	return KErrNone;
   1.307 +
   1.308 +/*	// Several CCamera white balance values dont have equivalent TMMWhiteBalControl values
   1.309 +	switch (aWhiteBalance)
   1.310 +		{
   1.311 +		case CCamera::EWBAuto:
   1.312 +			{
   1.313 +			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlAuto);
   1.314 +			}
   1.315 +		case CCamera::EWBDaylight:
   1.316 +			{
   1.317 +			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlSunLight);
   1.318 +			}
   1.319 +		case CCamera::EWBCloudy:
   1.320 +			{
   1.321 +			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlCloudy);
   1.322 +			}
   1.323 +		case CCamera::EWBTungsten:
   1.324 +			{
   1.325 +			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlTungsten);
   1.326 +			}
   1.327 +		case CCamera::EWBFluorescent:
   1.328 +			{
   1.329 +			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlFluorescent);
   1.330 +			}
   1.331 +		case CCamera::EWBFlash:
   1.332 +			{
   1.333 +			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlFlash);
   1.334 +			}
   1.335 +		case CCamera::EWBShade:
   1.336 +			{
   1.337 +			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlShade);
   1.338 +			}
   1.339 +		case CCamera::EWBHorizon:
   1.340 +			{
   1.341 +			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlHorizon);
   1.342 +			}
   1.343 +		default:
   1.344 +			{
   1.345 +			return KErrNotSupported;
   1.346 +			}
   1.347 +		}
   1.348 +*/	}
   1.349 +
   1.350 +TInt CMMCameraServerController::GetZoom(TInt& aZoom)
   1.351 +	{
   1.352 +	aZoom = iZoom;
   1.353 +	return KErrNone;
   1.354 +	}
   1.355 +
   1.356 +TInt CMMCameraServerController::GetDigitalZoom(TInt& aDigitalZoom)
   1.357 +	{
   1.358 +	aDigitalZoom = iDigitalZoom;
   1.359 +	return KErrNone;
   1.360 +	}
   1.361 +
   1.362 +TInt CMMCameraServerController::GetContrast(TInt& aContrast)
   1.363 +	{
   1.364 +	aContrast = iContrast;
   1.365 +	return KErrNone;
   1.366 +	}
   1.367 +
   1.368 +TInt CMMCameraServerController::GetBrightness(TInt& aBrightness)
   1.369 +	{
   1.370 +	aBrightness = iBrightness;
   1.371 +	return KErrNone;
   1.372 +//	return iCameraSensor.GetBrightness(aBrightness);
   1.373 +	}
   1.374 +
   1.375 +TInt CMMCameraServerController::GetFlash(CCamera::TFlash& aFlash)
   1.376 +	{
   1.377 +	aFlash = iFlash;
   1.378 +	return KErrNone;
   1.379 +	}
   1.380 +
   1.381 +TInt CMMCameraServerController::GetExposure(CCamera::TExposure& aExposure)
   1.382 +	{
   1.383 +	aExposure = iExposure;
   1.384 +	return KErrNone;
   1.385 +
   1.386 +	/*
   1.387 +	// Several CCamera exposure values dont have equivalent TMMExposureControl values
   1.388 +	TMMExposureControl exposure;
   1.389 +	TInt error = iCameraSensor.GetExposureControl(exposure);
   1.390 +	if (error != KErrNone)
   1.391 +		{
   1.392 +		return error;
   1.393 +		}
   1.394 +
   1.395 +	switch (exposure)
   1.396 +		{
   1.397 +		case EExposureControlAuto:
   1.398 +			{
   1.399 +			aExposure = CCamera::EExposureAuto;
   1.400 +			break;
   1.401 +			}
   1.402 +		case EExposureControlNight:
   1.403 +			{
   1.404 +			aExposure = CCamera::EExposureNight;
   1.405 +			break;
   1.406 +			}
   1.407 +		case EExposureControlBackLight:
   1.408 +			{
   1.409 +			aExposure = CCamera::EExposureBacklight;
   1.410 +			break;
   1.411 +			}
   1.412 +		case EExposureControlSpotLight:
   1.413 +			{
   1.414 +			aExposure = CCamera::EExposureCenter;
   1.415 +			break;
   1.416 +			}
   1.417 +		case EExposureControlSports:
   1.418 +			{
   1.419 +			aExposure = CCamera::EExposureSport;
   1.420 +			break;
   1.421 +			}
   1.422 +		case EExposureControlSnow:
   1.423 +			{
   1.424 +			aExposure = CCamera::EExposureSnow;
   1.425 +			break;
   1.426 +			}
   1.427 +		case EExposureControlBeach:
   1.428 +			{
   1.429 +			aExposure = CCamera::EExposureBeach;
   1.430 +			break;
   1.431 +			}
   1.432 +		default:
   1.433 +			{
   1.434 +			return KErrNotSupported;
   1.435 +			}
   1.436 +		}
   1.437 +
   1.438 +	return KErrNone;
   1.439 +*/	}
   1.440 +
   1.441 +TInt CMMCameraServerController::GetWhiteBalance(CCamera::TWhiteBalance& aWhiteBalance)
   1.442 +	{
   1.443 +	aWhiteBalance = iWhiteBalance;
   1.444 +	return KErrNone;
   1.445 +
   1.446 +	/*
   1.447 +	// Several CCamera white balance values dont have equivalent TMMWhiteBalControl values
   1.448 +	TMMWhiteBalControl whiteBal;
   1.449 +	TInt error = iCameraSensor.GetWhiteBalanceControl(whiteBal);
   1.450 +	if (error != KErrNone)
   1.451 +		{
   1.452 +		return error;
   1.453 +		}
   1.454 +
   1.455 +	switch (aWhiteBalance)
   1.456 +		{
   1.457 +		case EWhiteBalControlAuto:
   1.458 +			{
   1.459 +			aWhiteBalance = CCamera::EWBAuto;
   1.460 +			break;
   1.461 +			}
   1.462 +		case EWhiteBalControlSunLight:
   1.463 +			{
   1.464 +			aWhiteBalance = CCamera::EWBDaylight;
   1.465 +			break;
   1.466 +			}
   1.467 +		case EWhiteBalControlCloudy:
   1.468 +			{
   1.469 +			aWhiteBalance = CCamera::EWBCloudy;
   1.470 +			break;
   1.471 +			}
   1.472 +		case EWhiteBalControlTungsten:
   1.473 +			{
   1.474 +			aWhiteBalance = CCamera::EWBTungsten;
   1.475 +			break;
   1.476 +			}
   1.477 +		case EWhiteBalControlFluorescent:
   1.478 +			{
   1.479 +			aWhiteBalance = CCamera::EWBFluorescent;
   1.480 +			break;
   1.481 +			}
   1.482 +		case EWhiteBalControlFlash:
   1.483 +			{
   1.484 +			aWhiteBalance = CCamera::EWBFlash;
   1.485 +			break;
   1.486 +			}
   1.487 +		case EWhiteBalControlShade:
   1.488 +			{
   1.489 +			aWhiteBalance = CCamera::EWBShade;
   1.490 +			break;
   1.491 +			}
   1.492 +		case EWhiteBalControlHorizon:
   1.493 +			{
   1.494 +			aWhiteBalance = CCamera::EWBHorizon;
   1.495 +			break;
   1.496 +			}
   1.497 +		default:
   1.498 +			{
   1.499 +			return KErrNotSupported;
   1.500 +			}
   1.501 +		}
   1.502 +
   1.503 +	return KErrNone;
   1.504 +*/	}
   1.505 +
   1.506 +void CMMCameraServerController::Reset()
   1.507 +	{
   1.508 +	if (iViewFinderState == CCamera::CCameraV2DirectViewFinder::EViewFinderActive)
   1.509 +		{
   1.510 +		StopDirectViewFinder();
   1.511 +		}
   1.512 +	}
   1.513 +
   1.514 +
   1.515 +
   1.516 +
   1.517 +CMMCameraServerControllerQuery* CMMCameraServerControllerQuery::NewL()
   1.518 +	{
   1.519 +	CMMCameraServerControllerQuery* self = new (ELeave) CMMCameraServerControllerQuery();
   1.520 +	CleanupStack::PushL(self);
   1.521 +	self->ConstructL();
   1.522 +	CleanupStack::Pop(self);
   1.523 +	return self;
   1.524 +	}
   1.525 +
   1.526 +CMMCameraServerControllerQuery::~CMMCameraServerControllerQuery()
   1.527 +	{
   1.528 +	iServer.Close();
   1.529 +	}
   1.530 +
   1.531 +void CMMCameraServerControllerQuery::ConstructL()
   1.532 +	{
   1.533 +	User::LeaveIfError(iServer.Connect());
   1.534 +	}
   1.535 +
   1.536 +CMMCameraServerControllerQuery::CMMCameraServerControllerQuery()
   1.537 +	{
   1.538 +	}
   1.539 +
   1.540 +TInt CMMCameraServerControllerQuery::GetCamerasAvailable()
   1.541 +	{
   1.542 +	// Code to query MM server TBC
   1.543 +	return 1;
   1.544 +	}