1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/include/drivers/camerasc.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,460 @@
1.4 +// Copyright (c) 2004-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 the License "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 +// e32\include\drivers\camerasc.h
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalAll
1.24 + @prototype
1.25 +*/
1.26 +
1.27 +#ifndef __CAMERASC_H__
1.28 +#define __CAMERASC_H__
1.29 +
1.30 +#include <d32camerasc.h>
1.31 +#include <platform.h>
1.32 +#include <kernel/kpower.h>
1.33 +#include <e32ver.h>
1.34 +
1.35 +/** The default number of buffers available to the client. */
1.36 +const TInt KDefaultNumClientBuffers=6;
1.37 +
1.38 +/** The maximum number of client capture requests which may be outstanding at any time. */
1.39 +const TInt KMaxCamScRequestsPending=8;
1.40 +
1.41 +/**
1.42 +@internalAll
1.43 +@prototype
1.44 +*/
1.45 +struct SBufSpecList
1.46 + {
1.47 + /** The first entry of the buffer offset list. This list holds the offset from the start of the chunk
1.48 + for each buffer. This list is only valid if the flag KScFlagBufOffsetListInUse is set in
1.49 + TSharedChunkBufConfigBase::iFlags. */
1.50 + TInt iBufferOffset;
1.51 + TInt iBufferId;
1.52 + };
1.53 +
1.54 +/**
1.55 +@internalAll
1.56 +@prototype
1.57 +*/
1.58 +class TCameraSharedChunkBufConfig : public TSharedChunkBufConfigBase
1.59 + {
1.60 +public:
1.61 + struct SBufSpecList iSpec;
1.62 + };
1.63 +
1.64 +// Forward declarations
1.65 +class TImageBuffer;
1.66 +class DCameraScLdd;
1.67 +class DBufferManager;
1.68 +
1.69 +/**
1.70 +The physical device driver (PDD) base class for the camera driver.
1.71 +@internalAll
1.72 +@prototype
1.73 +*/
1.74 +class DCameraScPdd : public DBase
1.75 + {
1.76 +public:
1.77 + /**
1.78 + Return the DFC queue to be used by this device.
1.79 + @param aUnit The unit number for which to get the DFC queue.
1.80 + @return The DFC queue to use.
1.81 + */
1.82 + virtual TDfcQue* DfcQ(TInt aUnit)=0;
1.83 +
1.84 + /**
1.85 + Return the capabilities of this camera device.
1.86 + @param aCapsBuf A packaged TCameraCapsV02 object to be filled with the capabilities of the
1.87 + device. This descriptor is in kernel memory and can be accessed directly.
1.88 + @see TCameraCapsV02.
1.89 + */
1.90 + virtual void Caps(TDes8& aCapsBuf) const=0;
1.91 +
1.92 + /**
1.93 + Return data format information for a custom camera data format setting. Only required where support is
1.94 + required for a data format that isn't supported by the LDD. Platforms which don't require support
1.95 + for custom data settings need not implement this method.
1.96 + @param aConfigBuf A packaged TCameraConfigV02 object containing the current camera driver configuration
1.97 + (including an identifier for the custom setting required). This configuration object should be
1.98 + updated by the PDD with the appropriate settings for the data format concerned. This descriptor
1.99 + is in kernel memory and can be accessed directly.
1.100 + @return KErrNone if successful, otherwise one of the other system wide error codes.
1.101 + */
1.102 + virtual TInt SpecifyCustomConfig(TDes8& aConfigBuf);
1.103 +
1.104 + /**
1.105 + Return the shared chunk create information to be used by this device.
1.106 + @param aChunkCreateInfo A chunk create info. object to be to be filled with the settings
1.107 + required for this device.
1.108 + */
1.109 + virtual void GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo)=0;
1.110 +
1.111 + /**
1.112 + Configure or reconfigure the device using the the configuration supplied.
1.113 + @param aConfigBuf A packaged TCameraConfigV02 object which contains the new configuration settings.
1.114 + This descriptor is in kernel memory and can be accessed directly.
1.115 + @return KErrNone if successful, otherwise one of the other system wide error codes.
1.116 + @see TCameraConfigV02.
1.117 + */
1.118 + virtual TInt SetConfig(const TDesC8& aConfigBuf)=0;
1.119 +
1.120 + /**
1.121 + Start the camera - start pixel sourcing.
1.122 + @param aCaptureMode The capture mode to start. @see TDevCamCaptureMode.
1.123 + @param aLinAddr The linear address of the start of the first buffer to use for image capture.
1.124 + @param aPhysAddr The physical address that corresponds to the linear address: aLinAddr.
1.125 + @return KErrNone if successful;
1.126 + otherwise one of the other system wide error codes.
1.127 + */
1.128 + virtual TInt Start(TDevCamCaptureMode aCaptureMode,TLinAddr aLinAddr,TPhysAddr aPhysAddr)=0;
1.129 +
1.130 + /**
1.131 + Sets the address of the buffer into which the next image will be captured.
1.132 + @param aLinAddr The linear address of the start of the buffer to use to capture the image frame.
1.133 + @param aPhysAddr The physical address that corresponds to the linear address: aLinAddr.
1.134 + @return KErrNone if the capture has been initiated successfully;
1.135 + KErrNotReady if the device is unable to accept the request for the moment;
1.136 + otherwise one of the other system-wide error codes.
1.137 + */
1.138 + virtual TInt CaptureNextImage(TLinAddr aLinAddr,TPhysAddr aPhysAddr)=0;
1.139 +
1.140 + /**
1.141 + Stop the camera - stop pixel sourcing.
1.142 + @return KErrNone if successful, otherwise one of the other system wide error codes.
1.143 + */
1.144 + virtual TInt Stop()=0;
1.145 +
1.146 + /**
1.147 + Power down the camera.
1.148 + */
1.149 + virtual void PowerDown()=0;
1.150 +
1.151 + /**
1.152 + Queries the driver for the size of the structure to be passed to RDevCameraSc::Caps().
1.153 + */
1.154 + virtual TInt CapsSize()=0;
1.155 +
1.156 + /**
1.157 + Returns the supported frame sizes that correspond to the desired capture mode and pixel format passed in.
1.158 + @param aCaptureMode The capture mode for which to obtain the information.
1.159 + @param aUidPixelFormat The pixel format for which to obtain the information.
1.160 + @param aFrameSizeCapsBuf An appropriately sized buffer to be filled with the supported frame sizes.
1.161 + @return KErrNone, if successful,
1.162 + KErrArgument, if an invalid capture mode or pixel format is specified, or if aFrameSizeCapsBuf is too small;
1.163 + otherwise one of the other system-wide error codes.
1.164 + @see SDevCamFrameSize
1.165 + */
1.166 + virtual TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf)=0;
1.167 +
1.168 + /**
1.169 + Sets the sensor brightness to the desired setting.
1.170 +
1.171 + @param aValue A verified brightness setting.
1.172 + @return KErrNone if successful, KErrNotSupported if not supported.
1.173 + */
1.174 + virtual TInt SetBrightness(TUint aValue) = 0;
1.175 +
1.176 + // SYM_BRANCH: Add support for setting of Dynamic Attributes. Contrast.
1.177 + /**
1.178 + Sets the sensor contrast to the desired setting.
1.179 +
1.180 + @param aValue A verified contrast setting.
1.181 + @return KErrNone if successful, KErrNotSupported if not supported.
1.182 + */
1.183 + virtual TInt SetContrast(TUint aValue) = 0;
1.184 +
1.185 + // SYM_BRANCH: Add support for setting of Dynamic Attributes. Colour Effect.
1.186 + /**
1.187 + Sets the sensor color effect to the desired setting.
1.188 +
1.189 + @param aValue A verified color effect setting.
1.190 + @return KErrNone if successful, KErrNotSupported if not supported.
1.191 + */
1.192 + virtual TInt SetColorEffect(TUint aValue) = 0;
1.193 +
1.194 +public:
1.195 + DCameraScLdd* iLdd;
1.196 + };
1.197 +
1.198 +/**
1.199 +The logical device (factory class) for the camera driver.
1.200 +*/
1.201 +class DCameraScLddFactory : public DLogicalDevice
1.202 + {
1.203 +public:
1.204 + DCameraScLddFactory();
1.205 + virtual TInt Install();
1.206 + virtual void GetCaps(TDes8 &aDes) const;
1.207 + virtual TInt Create(DLogicalChannelBase*& aChannel);
1.208 + TBool IsUnitOpen(TInt aUnit);
1.209 + TInt SetUnitOpen(TInt aUnit,TBool aIsOpenSetting);
1.210 +private:
1.211 + /** Mask to keep track of which units have a channel open on them. */
1.212 + TUint iUnitsOpenMask;
1.213 + /** A mutex to protect access to the unit info. mask. */
1.214 + NFastMutex iUnitInfoMutex;
1.215 + };
1.216 +
1.217 +/**
1.218 +The class representing a single image buffer.
1.219 +*/
1.220 +class TImageBuffer : public SDblQueLink
1.221 + {
1.222 +public:
1.223 + TImageBuffer();
1.224 + ~TImageBuffer();
1.225 + TInt Create(DChunk* aChunk,TInt aOffset,TInt aSize,TInt aId,TBool aIsContiguous);
1.226 + void SyncMemoryBeforeDmaRead();
1.227 + void SyncMemoryAfterDmaRead();
1.228 +public:
1.229 + /** The buffer id */
1.230 + TInt iId;
1.231 + /** The chunk used for this buffer */
1.232 + DChunk* iChunk;
1.233 + /** The offset, in bytes, of the start of the buffer within the chunk. */
1.234 + TInt iChunkOffset;
1.235 + /** The size of the buffer in bytes. */
1.236 + TInt iSize;
1.237 + /** The virtual address of buffer. */
1.238 + TLinAddr iLinearAddress;
1.239 + /** The physical address of buffer. KPhysAddrInvalid if the buffer is not physically contiguous. */
1.240 + TPhysAddr iPhysicalAddress;
1.241 + /** A list of physical addresses for buffer pages. 0 if the buffer is physically contiguous. */
1.242 + TPhysAddr* iPhysicalPages;
1.243 + /** This is the result of the transfer into this buffer. */
1.244 + TInt iResult;
1.245 + };
1.246 +
1.247 +/**
1.248 +An object encapsulating an image capture request from the client.
1.249 +*/
1.250 +class TCameraScRequest : public SDblQueLink
1.251 + {
1.252 +public:
1.253 + inline TCameraScRequest()
1.254 + {}
1.255 +public:
1.256 + /** The request status associated with the request - used to signal completion of the request and pass back a
1.257 + completion code. */
1.258 + TRequestStatus* iStatus;
1.259 + };
1.260 +
1.261 +/**
1.262 +An object encapsulating a queue of image capture requests from the client.
1.263 +*/
1.264 +class TCameraScRequestQueue
1.265 + {
1.266 +public:
1.267 + TCameraScRequestQueue(NFastMutex* aMutexPtr);
1.268 + ~TCameraScRequestQueue();
1.269 + TInt Create(DThread* anOwningThread);
1.270 + TInt Add(TRequestStatus* aStatus);
1.271 + TRequestStatus* Remove();
1.272 + void Cancel(TRequestStatus* aStatus);
1.273 + void CancelAll();
1.274 + inline TBool IsEmpty();
1.275 +private:
1.276 + /** The queue of pending capture requests. */
1.277 + SDblQue iPendRequestQ;
1.278 + /** The queue of unused capture requests. */
1.279 + SDblQue iUnusedRequestQ;
1.280 + /** The actual array of request objects. */
1.281 + TCameraScRequest* iRequest[KMaxCamScRequestsPending];
1.282 + NFastMutex* iMutexPtr;
1.283 + DThread* iOwningThread;
1.284 + };
1.285 +
1.286 +/**
1.287 +The buffer manager base class.
1.288 +*/
1.289 +class DBufferManager : public DBase
1.290 + {
1.291 +public:
1.292 + DBufferManager(DCameraScLdd* aLdd);
1.293 + ~DBufferManager();
1.294 + TInt Create(TInt aNumBuffers,TInt aBufferSize);
1.295 + TInt Create(TCameraSharedChunkBufConfig& aBufConfig,TInt aChunkHandle,DThread* anOwningThread);
1.296 + void GetBufConfig(TCameraSharedChunkBufConfig& aBufConfig);
1.297 + void Reset();
1.298 + void Purge(TImageBuffer* aBuffer);
1.299 + TImageBuffer* GetImageForClient(TBool aRemoveLast);
1.300 + TImageBuffer* SetImageCaptured(TInt aResult);
1.301 + TInt ReleaseImage(TInt aChunkOffset);
1.302 + TImageBuffer* NextAvailableForCapture();
1.303 + TImageBuffer* FindInUseImage(TInt aChunkOffset);
1.304 +protected:
1.305 + TInt CreateBufferLists(TInt aNumBuffers);
1.306 + TInt CommitMemoryForBuffer(TInt aChunkOffset,TInt aSize,TBool& aIsContiguous);
1.307 +protected:
1.308 + /** The owning LDD object. */
1.309 + DCameraScLdd* iLdd;
1.310 + /** The chunk which contains the buffers. */
1.311 + DChunk* iChunk;
1.312 + /** The linear address in kernel process for the start of the chunk. */
1.313 + TLinAddr iChunkBase;
1.314 + /**< MMU mapping attributes that the chunk has actually been mapped with. */
1.315 + TUint32 iChunkMapAttr;
1.316 + /** The number of buffers. */
1.317 + TInt iNumBuffers;
1.318 + /** The actual array of buffer objects. */
1.319 + TImageBuffer* iImageBuffer;
1.320 + /** The buffer currently being filled by image capture. (Not in any list). */
1.321 + TImageBuffer* iCurrentBuffer;
1.322 + /** The next buffer to use for image capture. (Not in any list). */
1.323 + TImageBuffer* iNextBuffer;
1.324 + /** A queue of those buffers which are currently free. */
1.325 + SDblQue iFreeBufferQ;
1.326 + /** A queue of those buffers which currently contain captured images (and which aren't being used by the client). */
1.327 + SDblQue iCompletedBufferQ;
1.328 + /** A queue of those buffers which are currently being used by the client. */
1.329 + SDblQue iInUseBufferQ;
1.330 +private:
1.331 + friend class DCameraScLdd;
1.332 + };
1.333 +
1.334 +/**
1.335 +The configuration class that is specific for each capture mode. This allows the driver to maintain different configurations,
1.336 +one for each capture mode, and make switching between capture modes faster.
1.337 +*/
1.338 +class TCaptureModeConfig
1.339 + {
1.340 + private:
1.341 + /** The handle to the chunk that is returned to the user side code. */
1.342 + TInt iChunkHandle;
1.343 + /** The current configuration of the capture mode */
1.344 + TCameraConfigV02 iCamConfig;
1.345 + /** The current configuration of the chunk. */
1.346 + TCameraSharedChunkBufConfig* iBufConfig;
1.347 + /** The size in bytes of the chunk configuration info. structure. */
1.348 + TInt iBufConfigSize;
1.349 + /** The current frame height. */
1.350 + TInt iFrameHeight;
1.351 + /** The current frame width. */
1.352 + TInt iFrameWidth;
1.353 + /** The buffer manager. */
1.354 + DBufferManager* iBufManager;
1.355 + private:
1.356 + friend class DCameraScLdd;
1.357 + };
1.358 +
1.359 +/**
1.360 +The camera driver power handler class.
1.361 +*/
1.362 +class DCameraScPowerHandler : public DPowerHandler
1.363 + {
1.364 +public:
1.365 + DCameraScPowerHandler(DCameraScLdd* aChannel);
1.366 + // Inherited from DPowerHandler
1.367 + void PowerUp();
1.368 + void PowerDown(TPowerState aPowerState);
1.369 +private:
1.370 + DCameraScLdd* iChannel;
1.371 + };
1.372 +
1.373 +/**
1.374 +The logical channel class for the camera driver.
1.375 +*/
1.376 +class DCameraScLdd : public DLogicalChannel
1.377 + {
1.378 +public:
1.379 + enum TState
1.380 + {
1.381 + /** Channel open - but not configured. */
1.382 + EOpen,
1.383 + /** Channel configured - but inactive. */
1.384 + EConfigured,
1.385 + /** Channel is active - capturing images. */
1.386 + ECapturing
1.387 + };
1.388 +public:
1.389 + DCameraScLdd();
1.390 + virtual ~DCameraScLdd();
1.391 + // Inherited from DLogicalChannel
1.392 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.393 + virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
1.394 + virtual void HandleMsg(TMessageBase* aMsg);
1.395 + virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
1.396 + inline DThread* OwningThread();
1.397 + inline TInt CurrentFrameHeight();
1.398 + inline TInt CurrentFrameWidth();
1.399 + void Shutdown();
1.400 + virtual TInt ImageCaptureCallback(TDevCamCaptureMode aCaptureMode,TInt aResult,TLinAddr* aLinAddr,TPhysAddr* aPhysAddr);
1.401 + virtual void PanicClientThread(TInt aReason);
1.402 +private:
1.403 + TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
1.404 + TInt DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2);
1.405 + TInt DoCancel(TUint aMask);
1.406 + TInt SetCaptureMode(TInt aCaptureMode);
1.407 + TInt SetCamConfig(TInt aCaptureMode, const TDesC8* aCamConfigBuf);
1.408 + TInt SetBufConfig(TInt aCaptureMode, const TDesC8* aBufferConfigBuf,TInt aChunkHandle);
1.409 + TInt SetBufConfig(TInt aCaptureMode, TInt aNumBuffers);
1.410 + TInt ChunkClose(TInt aCaptureMode);
1.411 + TInt Start();
1.412 + TInt NotifyNewImage(TRequestStatus* aStatus);
1.413 + TInt ReleaseBuffer(TInt aChunkOffset);
1.414 + TInt DoSetConfig(TInt aCaptureMode, const TDesC8* aCamConfigBuf);
1.415 + TInt ValidateConfig(TInt aCaptureMode, TCameraConfigV02 &aConfig);
1.416 + TInt DoValidateConfig(TCameraCapsV02* aCamCaps, TInt &aCaptureMode, TCameraConfigV02 &aConfig);
1.417 + TInt DoStart();
1.418 + TInt ReAllocBufferConfigInfo(TInt aCaptureMode, TInt aNumBuffers);
1.419 + TInt ReAllocBufferConfigInfo(TInt aNumBuffers);
1.420 + TInt GetSensorCaps(TAny* a1);
1.421 + TInt GetFrameSizeCaps(TAny* a1, TAny* a2);
1.422 + TInt GetDynamicAttribute(TInt aAttribute, TUint& aValue);
1.423 + TInt SetDynamicAttribute(TInt aAttribute, TUint aValue);
1.424 + inline DCameraScPdd* Pdd();
1.425 + static void RestartDfc(TAny* aChannel);
1.426 + static void PowerUpDfc(TAny* aPtr);
1.427 + static void PowerDownDfc(TAny* aPtr);
1.428 +private:
1.429 + /** An array of configurations for each capture mode. */
1.430 + TCaptureModeConfig* iCaptureModeConfig;
1.431 + /** The unit number of this channel. */
1.432 + TInt iUnit;
1.433 + /** The operating state of the channel. */
1.434 + TState iState;
1.435 + /** A pointer to the owning client thread. */
1.436 + DThread* iOwningThread;
1.437 + /** The current capture mode of the camera. */
1.438 + TDevCamCaptureMode iCaptureMode;
1.439 + /** The pending request queue. */
1.440 + TCameraScRequestQueue iRequestQueue;
1.441 + /** A mutex to protect access to the buffer lists and the pending request list. */
1.442 + NFastMutex iMutex;
1.443 + /** The camera driver power handler. */
1.444 + DCameraScPowerHandler* iPowerHandler;
1.445 + /** DFC used to re-start the PDD following a data capture error. */
1.446 + TDfc iRestartDfc;
1.447 + /** DFC used to handle power down requests from the power manager before a transition into system shutdown/standby. */
1.448 + TDfc iPowerDownDfc;
1.449 + /** DFC used to handle power up requests from the power manager following a transition out of system standby. */
1.450 + TDfc iPowerUpDfc;
1.451 +
1.452 + // Used as a cache for values successfully set by SetDynamicAttribute().
1.453 + TUint iBrightnessValue;
1.454 + TUint iContrastValue;
1.455 + TUint iColorEffectValue;
1.456 +
1.457 + friend class DCameraScPowerHandler;
1.458 + friend class DBufferManager;
1.459 + };
1.460 +
1.461 +#include <drivers/camerasc.inl>
1.462 +
1.463 +#endif // __CAMERASC_H__