os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraservercontroller.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @internalComponent
    19 */
    20 
    21 #include "mmcameraserver.h"
    22 #include "mmcameraserversession.h"
    23 #include "mmcameraservercontroller.h"
    24 
    25 #include <graphics/surfacemanager.h>
    26 
    27 using namespace MMClient;
    28 using namespace MMVideoComponents;
    29 using namespace MMCameraComponents;
    30 
    31 static const TInt KMMCamHandleNumberBase = 500;
    32 const TInt KDefaultFrameRate = 30;
    33 
    34 CMMCameraServerController* CMMCameraServerController::NewL(TInt aCameraIndex)
    35 	{
    36 	CMMCameraServerController* self = new(ELeave) CMMCameraServerController(aCameraIndex);
    37 	CleanupStack::PushL(self);
    38 	self->ConstructL();
    39 	CleanupStack::Pop(self);
    40 	return self;	
    41 	}
    42 
    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)
    50 	{
    51 	}
    52 
    53 void CMMCameraServerController::ConstructL()
    54 	{	
    55 	User::LeaveIfError(iMMServer.Connect()); // Connect to the MM server
    56 
    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();
    62 
    63 	// Open stream, stream container and camera/graphics sink components
    64 	User::LeaveIfError(iMMStreamContainer.Open());
    65 	User::LeaveIfError(iMMStream.Open(iMMStreamContainer));
    66 
    67 	User::LeaveIfError(iCameraViewFinder.Open(*cameraViewFinderChar));
    68 	User::LeaveIfError(iMMStream.Append(iCameraViewFinder));
    69 
    70 	User::LeaveIfError(iGraphicsSink.Open(*graphicsSinkChar));
    71 	User::LeaveIfError(iMMStream.Append(iGraphicsSink));
    72 
    73 	User::LeaveIfError(iCameraSensor.Open(*cameraSensorChar));
    74 	User::LeaveIfError(iMMStream.Append(iCameraSensor));
    75 	}
    76 
    77 CMMCameraServerController::~CMMCameraServerController()
    78 	{
    79 	iCameraCapture.Close();
    80 	iCameraSensor.Close();
    81 	iGraphicsSink.Close();
    82 	iCameraViewFinder.Close();
    83 	iMMStream.Close();
    84 	iMMStreamContainer.Close();
    85 	iMMServer.Close();
    86 
    87 	iCamCntrlLink.Deque();
    88 	iCamCntrlLink.iNext = NULL;
    89 	}
    90 
    91 TInt CMMCameraServerController::CameraIndex() const
    92 	{
    93 	return iCameraIndex;
    94 	}
    95 
    96 TInt CMMCameraServerController::CameraHandle() const
    97 	{
    98 	return iCameraHandle;
    99 	}
   100 
   101 void CMMCameraServerController::PrepareDirectViewFinderL(TDirectViewFinderInfo& aDirectViewFinderInfo)
   102 	{
   103 	// Default mode - One Shot setting off
   104 	User::LeaveIfError(iCameraSensor.SetSensorOneShot(EFalse));
   105 
   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));
   112 
   113 	User::LeaveIfError(iMMServer.Commit(iMMStreamContainer));
   114 
   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;
   118 	}
   119 
   120 TInt CMMCameraServerController::StartDirectViewFinder()
   121 	{
   122 	TRequestStatus status;
   123 	iMMStream.Start(status);
   124 	User::WaitForRequest(status);
   125 	if(status.Int() == KErrNone)
   126 		{
   127 		iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderActive;
   128 		}
   129 
   130 	return status.Int();
   131 	}
   132 
   133 void CMMCameraServerController::StopDirectViewFinder()
   134 	{
   135 	TRequestStatus status;
   136 	iMMStream.Stop(status);
   137 	User::WaitForRequest(status);
   138 	iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderInActive;
   139 	}
   140 
   141 void CMMCameraServerController::PauseDirectViewFinder()
   142 	{
   143 	TRequestStatus status;
   144 	iMMStream.Pause(status);
   145 	User::WaitForRequest(status);
   146 	iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderPause;
   147 	}
   148 
   149 void CMMCameraServerController::ResumeDirectViewFinder()
   150 	{
   151 	TRequestStatus status;
   152 	iMMStream.Resume(status);
   153 	User::WaitForRequest(status);
   154 	iViewFinderState = CCamera::CCameraV2DirectViewFinder::EViewFinderActive;
   155 	}
   156 
   157 CCamera::CCameraV2DirectViewFinder::TViewFinderState CMMCameraServerController::GetDirectViewFinderState() const
   158 	{
   159 	return iViewFinderState;
   160 	}
   161 
   162 TInt CMMCameraServerController::SetDirectViewFinderMirror(const TBool aMirror)
   163 	{
   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)
   166 	if (aMirror)
   167 		{
   168 		return iCameraSensor.SetMirrorType(EMirrorHorizontal);
   169 		}
   170 	else
   171 		{
   172 		return iCameraSensor.SetMirrorType(EMirrorNone);
   173 		}
   174 	}
   175 
   176 TInt CMMCameraServerController::GetDirectViewFinderMirror(TBool& aMirror)
   177 	{
   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)
   180 	TMMMirror mirror;
   181 	TInt error = iCameraSensor.GetMirrorType(mirror);
   182 	if (error != KErrNone)
   183 		{
   184 		return error;
   185 		}
   186 
   187 	if (mirror == EMirrorHorizontal)
   188 		{
   189 		aMirror = ETrue;
   190 		}
   191 	else
   192 		{
   193 		aMirror = EFalse;
   194 		}
   195 
   196 	return KErrNone;
   197 	}
   198 
   199 TInt CMMCameraServerController::DirectViewFinderProperties(TInt& aScreenNum, TRect& aScreenRect, TRect& aClipRect)
   200 	{
   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)
   204 		{
   205 		aScreenNum = screenNumber;
   206 		TUint width;
   207 		TUint height;
   208 		TInt error = iCameraViewFinder.GetFrameDimensions(width, height);
   209 		if (error ==KErrNone)
   210 			{
   211 			aScreenRect.SetWidth(width);
   212 			aScreenRect.SetHeight(height);
   213 			aClipRect = iClipRect;
   214 			return KErrNone;
   215 			}
   216 		}
   217 	else
   218 		{
   219 		aScreenNum = -1;
   220 		}
   221 
   222 	return error;	
   223 	}
   224 
   225 TInt CMMCameraServerController::SetZoom(const TInt aZoom)
   226 	{
   227 	iZoom = aZoom;
   228 	return KErrNone;
   229 	}
   230 
   231 TInt CMMCameraServerController::SetDigitalZoom(const TInt aDigitalZoom)
   232 	{
   233 	iDigitalZoom = aDigitalZoom;
   234 	return KErrNone;
   235 	}
   236 
   237 TInt CMMCameraServerController::SetContrast(const TInt aContrast)
   238 	{
   239 	iContrast = aContrast;
   240 	return KErrNone;
   241 	}
   242 
   243 TInt CMMCameraServerController::SetBrightness(const TInt aBrightness)
   244 	{
   245 	iBrightness = aBrightness;
   246 	return KErrNone;
   247 //	return iCameraSensor.SetBrightness(aBrightness);
   248 	}
   249 
   250 TInt CMMCameraServerController::SetFlash(const CCamera::TFlash aFlash)
   251 	{
   252 	iFlash = aFlash;
   253 	return KErrNone;
   254 	}
   255 
   256 TInt CMMCameraServerController::SetExposure(const CCamera::TExposure aExposure)
   257 	{
   258 	iExposure = aExposure;
   259 	return KErrNone;
   260 
   261 	/*
   262 	// Several CCamera exposure values dont have equivalent TMMExposureControl values
   263 	switch (aExposure)
   264 		{
   265 		case CCamera::EExposureAuto:
   266 			{
   267 			return iCameraSensor.SetExposureControl(EExposureControlAuto);
   268 			}
   269 		case CCamera::EExposureNight:
   270 			{
   271 			return iCameraSensor.SetExposureControl(EExposureControlNight);
   272 			}
   273 		case CCamera::EExposureBacklight:
   274 			{
   275 			return iCameraSensor.SetExposureControl(EExposureControlBackLight);
   276 			}
   277 		case CCamera::EExposureCenter:
   278 			{
   279 			return iCameraSensor.SetExposureControl(EExposureControlSpotLight);
   280 			}
   281 		case CCamera::EExposureSport:
   282 			{
   283 			return iCameraSensor.SetExposureControl(EExposureControlSports);
   284 			}
   285 		case CCamera::EExposureSnow:
   286 			{
   287 			return iCameraSensor.SetExposureControl(EExposureControlSnow);
   288 			}
   289 		case CCamera::EExposureBeach:
   290 			{
   291 			return iCameraSensor.SetExposureControl(EExposureControlBeach);
   292 			}
   293 		default:
   294 			{
   295 			return KErrNotSupported;
   296 			}
   297 		}
   298 */	}
   299 
   300 TInt CMMCameraServerController::SetWhiteBalance(const CCamera::TWhiteBalance aWhiteBalance)
   301 	{
   302 	iWhiteBalance = aWhiteBalance;
   303 	return KErrNone;
   304 
   305 /*	// Several CCamera white balance values dont have equivalent TMMWhiteBalControl values
   306 	switch (aWhiteBalance)
   307 		{
   308 		case CCamera::EWBAuto:
   309 			{
   310 			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlAuto);
   311 			}
   312 		case CCamera::EWBDaylight:
   313 			{
   314 			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlSunLight);
   315 			}
   316 		case CCamera::EWBCloudy:
   317 			{
   318 			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlCloudy);
   319 			}
   320 		case CCamera::EWBTungsten:
   321 			{
   322 			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlTungsten);
   323 			}
   324 		case CCamera::EWBFluorescent:
   325 			{
   326 			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlFluorescent);
   327 			}
   328 		case CCamera::EWBFlash:
   329 			{
   330 			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlFlash);
   331 			}
   332 		case CCamera::EWBShade:
   333 			{
   334 			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlShade);
   335 			}
   336 		case CCamera::EWBHorizon:
   337 			{
   338 			return iCameraSensor.SetWhiteBalanceControl(EWhiteBalControlHorizon);
   339 			}
   340 		default:
   341 			{
   342 			return KErrNotSupported;
   343 			}
   344 		}
   345 */	}
   346 
   347 TInt CMMCameraServerController::GetZoom(TInt& aZoom)
   348 	{
   349 	aZoom = iZoom;
   350 	return KErrNone;
   351 	}
   352 
   353 TInt CMMCameraServerController::GetDigitalZoom(TInt& aDigitalZoom)
   354 	{
   355 	aDigitalZoom = iDigitalZoom;
   356 	return KErrNone;
   357 	}
   358 
   359 TInt CMMCameraServerController::GetContrast(TInt& aContrast)
   360 	{
   361 	aContrast = iContrast;
   362 	return KErrNone;
   363 	}
   364 
   365 TInt CMMCameraServerController::GetBrightness(TInt& aBrightness)
   366 	{
   367 	aBrightness = iBrightness;
   368 	return KErrNone;
   369 //	return iCameraSensor.GetBrightness(aBrightness);
   370 	}
   371 
   372 TInt CMMCameraServerController::GetFlash(CCamera::TFlash& aFlash)
   373 	{
   374 	aFlash = iFlash;
   375 	return KErrNone;
   376 	}
   377 
   378 TInt CMMCameraServerController::GetExposure(CCamera::TExposure& aExposure)
   379 	{
   380 	aExposure = iExposure;
   381 	return KErrNone;
   382 
   383 	/*
   384 	// Several CCamera exposure values dont have equivalent TMMExposureControl values
   385 	TMMExposureControl exposure;
   386 	TInt error = iCameraSensor.GetExposureControl(exposure);
   387 	if (error != KErrNone)
   388 		{
   389 		return error;
   390 		}
   391 
   392 	switch (exposure)
   393 		{
   394 		case EExposureControlAuto:
   395 			{
   396 			aExposure = CCamera::EExposureAuto;
   397 			break;
   398 			}
   399 		case EExposureControlNight:
   400 			{
   401 			aExposure = CCamera::EExposureNight;
   402 			break;
   403 			}
   404 		case EExposureControlBackLight:
   405 			{
   406 			aExposure = CCamera::EExposureBacklight;
   407 			break;
   408 			}
   409 		case EExposureControlSpotLight:
   410 			{
   411 			aExposure = CCamera::EExposureCenter;
   412 			break;
   413 			}
   414 		case EExposureControlSports:
   415 			{
   416 			aExposure = CCamera::EExposureSport;
   417 			break;
   418 			}
   419 		case EExposureControlSnow:
   420 			{
   421 			aExposure = CCamera::EExposureSnow;
   422 			break;
   423 			}
   424 		case EExposureControlBeach:
   425 			{
   426 			aExposure = CCamera::EExposureBeach;
   427 			break;
   428 			}
   429 		default:
   430 			{
   431 			return KErrNotSupported;
   432 			}
   433 		}
   434 
   435 	return KErrNone;
   436 */	}
   437 
   438 TInt CMMCameraServerController::GetWhiteBalance(CCamera::TWhiteBalance& aWhiteBalance)
   439 	{
   440 	aWhiteBalance = iWhiteBalance;
   441 	return KErrNone;
   442 
   443 	/*
   444 	// Several CCamera white balance values dont have equivalent TMMWhiteBalControl values
   445 	TMMWhiteBalControl whiteBal;
   446 	TInt error = iCameraSensor.GetWhiteBalanceControl(whiteBal);
   447 	if (error != KErrNone)
   448 		{
   449 		return error;
   450 		}
   451 
   452 	switch (aWhiteBalance)
   453 		{
   454 		case EWhiteBalControlAuto:
   455 			{
   456 			aWhiteBalance = CCamera::EWBAuto;
   457 			break;
   458 			}
   459 		case EWhiteBalControlSunLight:
   460 			{
   461 			aWhiteBalance = CCamera::EWBDaylight;
   462 			break;
   463 			}
   464 		case EWhiteBalControlCloudy:
   465 			{
   466 			aWhiteBalance = CCamera::EWBCloudy;
   467 			break;
   468 			}
   469 		case EWhiteBalControlTungsten:
   470 			{
   471 			aWhiteBalance = CCamera::EWBTungsten;
   472 			break;
   473 			}
   474 		case EWhiteBalControlFluorescent:
   475 			{
   476 			aWhiteBalance = CCamera::EWBFluorescent;
   477 			break;
   478 			}
   479 		case EWhiteBalControlFlash:
   480 			{
   481 			aWhiteBalance = CCamera::EWBFlash;
   482 			break;
   483 			}
   484 		case EWhiteBalControlShade:
   485 			{
   486 			aWhiteBalance = CCamera::EWBShade;
   487 			break;
   488 			}
   489 		case EWhiteBalControlHorizon:
   490 			{
   491 			aWhiteBalance = CCamera::EWBHorizon;
   492 			break;
   493 			}
   494 		default:
   495 			{
   496 			return KErrNotSupported;
   497 			}
   498 		}
   499 
   500 	return KErrNone;
   501 */	}
   502 
   503 void CMMCameraServerController::Reset()
   504 	{
   505 	if (iViewFinderState == CCamera::CCameraV2DirectViewFinder::EViewFinderActive)
   506 		{
   507 		StopDirectViewFinder();
   508 		}
   509 	}
   510 
   511 
   512 
   513 
   514 CMMCameraServerControllerQuery* CMMCameraServerControllerQuery::NewL()
   515 	{
   516 	CMMCameraServerControllerQuery* self = new (ELeave) CMMCameraServerControllerQuery();
   517 	CleanupStack::PushL(self);
   518 	self->ConstructL();
   519 	CleanupStack::Pop(self);
   520 	return self;
   521 	}
   522 
   523 CMMCameraServerControllerQuery::~CMMCameraServerControllerQuery()
   524 	{
   525 	iServer.Close();
   526 	}
   527 
   528 void CMMCameraServerControllerQuery::ConstructL()
   529 	{
   530 	User::LeaveIfError(iServer.Connect());
   531 	}
   532 
   533 CMMCameraServerControllerQuery::CMMCameraServerControllerQuery()
   534 	{
   535 	}
   536 
   537 TInt CMMCameraServerControllerQuery::GetCamerasAvailable()
   538 	{
   539 	// Code to query MM server TBC
   540 	return 1;
   541 	}