sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\include\drivers\camerasc.h sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalAll sl@0: @prototype sl@0: */ sl@0: sl@0: #ifndef __CAMERASC_H__ sl@0: #define __CAMERASC_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: /** The default number of buffers available to the client. */ sl@0: const TInt KDefaultNumClientBuffers=6; sl@0: sl@0: /** The maximum number of client capture requests which may be outstanding at any time. */ sl@0: const TInt KMaxCamScRequestsPending=8; sl@0: sl@0: /** sl@0: @internalAll sl@0: @prototype sl@0: */ sl@0: struct SBufSpecList sl@0: { sl@0: /** The first entry of the buffer offset list. This list holds the offset from the start of the chunk sl@0: for each buffer. This list is only valid if the flag KScFlagBufOffsetListInUse is set in sl@0: TSharedChunkBufConfigBase::iFlags. */ sl@0: TInt iBufferOffset; sl@0: TInt iBufferId; sl@0: }; sl@0: sl@0: /** sl@0: @internalAll sl@0: @prototype sl@0: */ sl@0: class TCameraSharedChunkBufConfig : public TSharedChunkBufConfigBase sl@0: { sl@0: public: sl@0: struct SBufSpecList iSpec; sl@0: }; sl@0: sl@0: // Forward declarations sl@0: class TImageBuffer; sl@0: class DCameraScLdd; sl@0: class DBufferManager; sl@0: sl@0: /** sl@0: The physical device driver (PDD) base class for the camera driver. sl@0: @internalAll sl@0: @prototype sl@0: */ sl@0: class DCameraScPdd : public DBase sl@0: { sl@0: public: sl@0: /** sl@0: Return the DFC queue to be used by this device. sl@0: @param aUnit The unit number for which to get the DFC queue. sl@0: @return The DFC queue to use. sl@0: */ sl@0: virtual TDfcQue* DfcQ(TInt aUnit)=0; sl@0: sl@0: /** sl@0: Return the capabilities of this camera device. sl@0: @param aCapsBuf A packaged TCameraCapsV02 object to be filled with the capabilities of the sl@0: device. This descriptor is in kernel memory and can be accessed directly. sl@0: @see TCameraCapsV02. sl@0: */ sl@0: virtual void Caps(TDes8& aCapsBuf) const=0; sl@0: sl@0: /** sl@0: Return data format information for a custom camera data format setting. Only required where support is sl@0: required for a data format that isn't supported by the LDD. Platforms which don't require support sl@0: for custom data settings need not implement this method. sl@0: @param aConfigBuf A packaged TCameraConfigV02 object containing the current camera driver configuration sl@0: (including an identifier for the custom setting required). This configuration object should be sl@0: updated by the PDD with the appropriate settings for the data format concerned. This descriptor sl@0: is in kernel memory and can be accessed directly. sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: */ sl@0: virtual TInt SpecifyCustomConfig(TDes8& aConfigBuf); sl@0: sl@0: /** sl@0: Return the shared chunk create information to be used by this device. sl@0: @param aChunkCreateInfo A chunk create info. object to be to be filled with the settings sl@0: required for this device. sl@0: */ sl@0: virtual void GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo)=0; sl@0: sl@0: /** sl@0: Configure or reconfigure the device using the the configuration supplied. sl@0: @param aConfigBuf A packaged TCameraConfigV02 object which contains the new configuration settings. sl@0: This descriptor is in kernel memory and can be accessed directly. sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: @see TCameraConfigV02. sl@0: */ sl@0: virtual TInt SetConfig(const TDesC8& aConfigBuf)=0; sl@0: sl@0: /** sl@0: Start the camera - start pixel sourcing. sl@0: @param aCaptureMode The capture mode to start. @see TDevCamCaptureMode. sl@0: @param aLinAddr The linear address of the start of the first buffer to use for image capture. sl@0: @param aPhysAddr The physical address that corresponds to the linear address: aLinAddr. sl@0: @return KErrNone if successful; sl@0: otherwise one of the other system wide error codes. sl@0: */ sl@0: virtual TInt Start(TDevCamCaptureMode aCaptureMode,TLinAddr aLinAddr,TPhysAddr aPhysAddr)=0; sl@0: sl@0: /** sl@0: Sets the address of the buffer into which the next image will be captured. sl@0: @param aLinAddr The linear address of the start of the buffer to use to capture the image frame. sl@0: @param aPhysAddr The physical address that corresponds to the linear address: aLinAddr. sl@0: @return KErrNone if the capture has been initiated successfully; sl@0: KErrNotReady if the device is unable to accept the request for the moment; sl@0: otherwise one of the other system-wide error codes. sl@0: */ sl@0: virtual TInt CaptureNextImage(TLinAddr aLinAddr,TPhysAddr aPhysAddr)=0; sl@0: sl@0: /** sl@0: Stop the camera - stop pixel sourcing. sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: */ sl@0: virtual TInt Stop()=0; sl@0: sl@0: /** sl@0: Power down the camera. sl@0: */ sl@0: virtual void PowerDown()=0; sl@0: sl@0: /** sl@0: Queries the driver for the size of the structure to be passed to RDevCameraSc::Caps(). sl@0: */ sl@0: virtual TInt CapsSize()=0; sl@0: sl@0: /** sl@0: Returns the supported frame sizes that correspond to the desired capture mode and pixel format passed in. sl@0: @param aCaptureMode The capture mode for which to obtain the information. sl@0: @param aUidPixelFormat The pixel format for which to obtain the information. sl@0: @param aFrameSizeCapsBuf An appropriately sized buffer to be filled with the supported frame sizes. sl@0: @return KErrNone, if successful, sl@0: KErrArgument, if an invalid capture mode or pixel format is specified, or if aFrameSizeCapsBuf is too small; sl@0: otherwise one of the other system-wide error codes. sl@0: @see SDevCamFrameSize sl@0: */ sl@0: virtual TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf)=0; sl@0: sl@0: /** sl@0: Sets the sensor brightness to the desired setting. sl@0: sl@0: @param aValue A verified brightness setting. sl@0: @return KErrNone if successful, KErrNotSupported if not supported. sl@0: */ sl@0: virtual TInt SetBrightness(TUint aValue) = 0; sl@0: sl@0: // SYM_BRANCH: Add support for setting of Dynamic Attributes. Contrast. sl@0: /** sl@0: Sets the sensor contrast to the desired setting. sl@0: sl@0: @param aValue A verified contrast setting. sl@0: @return KErrNone if successful, KErrNotSupported if not supported. sl@0: */ sl@0: virtual TInt SetContrast(TUint aValue) = 0; sl@0: sl@0: // SYM_BRANCH: Add support for setting of Dynamic Attributes. Colour Effect. sl@0: /** sl@0: Sets the sensor color effect to the desired setting. sl@0: sl@0: @param aValue A verified color effect setting. sl@0: @return KErrNone if successful, KErrNotSupported if not supported. sl@0: */ sl@0: virtual TInt SetColorEffect(TUint aValue) = 0; sl@0: sl@0: public: sl@0: DCameraScLdd* iLdd; sl@0: }; sl@0: sl@0: /** sl@0: The logical device (factory class) for the camera driver. sl@0: */ sl@0: class DCameraScLddFactory : public DLogicalDevice sl@0: { sl@0: public: sl@0: DCameraScLddFactory(); sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8 &aDes) const; sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); sl@0: TBool IsUnitOpen(TInt aUnit); sl@0: TInt SetUnitOpen(TInt aUnit,TBool aIsOpenSetting); sl@0: private: sl@0: /** Mask to keep track of which units have a channel open on them. */ sl@0: TUint iUnitsOpenMask; sl@0: /** A mutex to protect access to the unit info. mask. */ sl@0: NFastMutex iUnitInfoMutex; sl@0: }; sl@0: sl@0: /** sl@0: The class representing a single image buffer. sl@0: */ sl@0: class TImageBuffer : public SDblQueLink sl@0: { sl@0: public: sl@0: TImageBuffer(); sl@0: ~TImageBuffer(); sl@0: TInt Create(DChunk* aChunk,TInt aOffset,TInt aSize,TInt aId,TBool aIsContiguous); sl@0: void SyncMemoryBeforeDmaRead(); sl@0: void SyncMemoryAfterDmaRead(); sl@0: public: sl@0: /** The buffer id */ sl@0: TInt iId; sl@0: /** The chunk used for this buffer */ sl@0: DChunk* iChunk; sl@0: /** The offset, in bytes, of the start of the buffer within the chunk. */ sl@0: TInt iChunkOffset; sl@0: /** The size of the buffer in bytes. */ sl@0: TInt iSize; sl@0: /** The virtual address of buffer. */ sl@0: TLinAddr iLinearAddress; sl@0: /** The physical address of buffer. KPhysAddrInvalid if the buffer is not physically contiguous. */ sl@0: TPhysAddr iPhysicalAddress; sl@0: /** A list of physical addresses for buffer pages. 0 if the buffer is physically contiguous. */ sl@0: TPhysAddr* iPhysicalPages; sl@0: /** This is the result of the transfer into this buffer. */ sl@0: TInt iResult; sl@0: }; sl@0: sl@0: /** sl@0: An object encapsulating an image capture request from the client. sl@0: */ sl@0: class TCameraScRequest : public SDblQueLink sl@0: { sl@0: public: sl@0: inline TCameraScRequest() sl@0: {} sl@0: public: sl@0: /** The request status associated with the request - used to signal completion of the request and pass back a sl@0: completion code. */ sl@0: TRequestStatus* iStatus; sl@0: }; sl@0: sl@0: /** sl@0: An object encapsulating a queue of image capture requests from the client. sl@0: */ sl@0: class TCameraScRequestQueue sl@0: { sl@0: public: sl@0: TCameraScRequestQueue(NFastMutex* aMutexPtr); sl@0: ~TCameraScRequestQueue(); sl@0: TInt Create(DThread* anOwningThread); sl@0: TInt Add(TRequestStatus* aStatus); sl@0: TRequestStatus* Remove(); sl@0: void Cancel(TRequestStatus* aStatus); sl@0: void CancelAll(); sl@0: inline TBool IsEmpty(); sl@0: private: sl@0: /** The queue of pending capture requests. */ sl@0: SDblQue iPendRequestQ; sl@0: /** The queue of unused capture requests. */ sl@0: SDblQue iUnusedRequestQ; sl@0: /** The actual array of request objects. */ sl@0: TCameraScRequest* iRequest[KMaxCamScRequestsPending]; sl@0: NFastMutex* iMutexPtr; sl@0: DThread* iOwningThread; sl@0: }; sl@0: sl@0: /** sl@0: The buffer manager base class. sl@0: */ sl@0: class DBufferManager : public DBase sl@0: { sl@0: public: sl@0: DBufferManager(DCameraScLdd* aLdd); sl@0: ~DBufferManager(); sl@0: TInt Create(TInt aNumBuffers,TInt aBufferSize); sl@0: TInt Create(TCameraSharedChunkBufConfig& aBufConfig,TInt aChunkHandle,DThread* anOwningThread); sl@0: void GetBufConfig(TCameraSharedChunkBufConfig& aBufConfig); sl@0: void Reset(); sl@0: void Purge(TImageBuffer* aBuffer); sl@0: TImageBuffer* GetImageForClient(TBool aRemoveLast); sl@0: TImageBuffer* SetImageCaptured(TInt aResult); sl@0: TInt ReleaseImage(TInt aChunkOffset); sl@0: TImageBuffer* NextAvailableForCapture(); sl@0: TImageBuffer* FindInUseImage(TInt aChunkOffset); sl@0: protected: sl@0: TInt CreateBufferLists(TInt aNumBuffers); sl@0: TInt CommitMemoryForBuffer(TInt aChunkOffset,TInt aSize,TBool& aIsContiguous); sl@0: protected: sl@0: /** The owning LDD object. */ sl@0: DCameraScLdd* iLdd; sl@0: /** The chunk which contains the buffers. */ sl@0: DChunk* iChunk; sl@0: /** The linear address in kernel process for the start of the chunk. */ sl@0: TLinAddr iChunkBase; sl@0: /**< MMU mapping attributes that the chunk has actually been mapped with. */ sl@0: TUint32 iChunkMapAttr; sl@0: /** The number of buffers. */ sl@0: TInt iNumBuffers; sl@0: /** The actual array of buffer objects. */ sl@0: TImageBuffer* iImageBuffer; sl@0: /** The buffer currently being filled by image capture. (Not in any list). */ sl@0: TImageBuffer* iCurrentBuffer; sl@0: /** The next buffer to use for image capture. (Not in any list). */ sl@0: TImageBuffer* iNextBuffer; sl@0: /** A queue of those buffers which are currently free. */ sl@0: SDblQue iFreeBufferQ; sl@0: /** A queue of those buffers which currently contain captured images (and which aren't being used by the client). */ sl@0: SDblQue iCompletedBufferQ; sl@0: /** A queue of those buffers which are currently being used by the client. */ sl@0: SDblQue iInUseBufferQ; sl@0: private: sl@0: friend class DCameraScLdd; sl@0: }; sl@0: sl@0: /** sl@0: The configuration class that is specific for each capture mode. This allows the driver to maintain different configurations, sl@0: one for each capture mode, and make switching between capture modes faster. sl@0: */ sl@0: class TCaptureModeConfig sl@0: { sl@0: private: sl@0: /** The handle to the chunk that is returned to the user side code. */ sl@0: TInt iChunkHandle; sl@0: /** The current configuration of the capture mode */ sl@0: TCameraConfigV02 iCamConfig; sl@0: /** The current configuration of the chunk. */ sl@0: TCameraSharedChunkBufConfig* iBufConfig; sl@0: /** The size in bytes of the chunk configuration info. structure. */ sl@0: TInt iBufConfigSize; sl@0: /** The current frame height. */ sl@0: TInt iFrameHeight; sl@0: /** The current frame width. */ sl@0: TInt iFrameWidth; sl@0: /** The buffer manager. */ sl@0: DBufferManager* iBufManager; sl@0: private: sl@0: friend class DCameraScLdd; sl@0: }; sl@0: sl@0: /** sl@0: The camera driver power handler class. sl@0: */ sl@0: class DCameraScPowerHandler : public DPowerHandler sl@0: { sl@0: public: sl@0: DCameraScPowerHandler(DCameraScLdd* aChannel); sl@0: // Inherited from DPowerHandler sl@0: void PowerUp(); sl@0: void PowerDown(TPowerState aPowerState); sl@0: private: sl@0: DCameraScLdd* iChannel; sl@0: }; sl@0: sl@0: /** sl@0: The logical channel class for the camera driver. sl@0: */ sl@0: class DCameraScLdd : public DLogicalChannel sl@0: { sl@0: public: sl@0: enum TState sl@0: { sl@0: /** Channel open - but not configured. */ sl@0: EOpen, sl@0: /** Channel configured - but inactive. */ sl@0: EConfigured, sl@0: /** Channel is active - capturing images. */ sl@0: ECapturing sl@0: }; sl@0: public: sl@0: DCameraScLdd(); sl@0: virtual ~DCameraScLdd(); sl@0: // Inherited from DLogicalChannel sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); sl@0: virtual void HandleMsg(TMessageBase* aMsg); sl@0: virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType); sl@0: inline DThread* OwningThread(); sl@0: inline TInt CurrentFrameHeight(); sl@0: inline TInt CurrentFrameWidth(); sl@0: void Shutdown(); sl@0: virtual TInt ImageCaptureCallback(TDevCamCaptureMode aCaptureMode,TInt aResult,TLinAddr* aLinAddr,TPhysAddr* aPhysAddr); sl@0: virtual void PanicClientThread(TInt aReason); sl@0: private: sl@0: TInt DoControl(TInt aFunction, TAny* a1, TAny* a2); sl@0: TInt DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2); sl@0: TInt DoCancel(TUint aMask); sl@0: TInt SetCaptureMode(TInt aCaptureMode); sl@0: TInt SetCamConfig(TInt aCaptureMode, const TDesC8* aCamConfigBuf); sl@0: TInt SetBufConfig(TInt aCaptureMode, const TDesC8* aBufferConfigBuf,TInt aChunkHandle); sl@0: TInt SetBufConfig(TInt aCaptureMode, TInt aNumBuffers); sl@0: TInt ChunkClose(TInt aCaptureMode); sl@0: TInt Start(); sl@0: TInt NotifyNewImage(TRequestStatus* aStatus); sl@0: TInt ReleaseBuffer(TInt aChunkOffset); sl@0: TInt DoSetConfig(TInt aCaptureMode, const TDesC8* aCamConfigBuf); sl@0: TInt ValidateConfig(TInt aCaptureMode, TCameraConfigV02 &aConfig); sl@0: TInt DoValidateConfig(TCameraCapsV02* aCamCaps, TInt &aCaptureMode, TCameraConfigV02 &aConfig); sl@0: TInt DoStart(); sl@0: TInt ReAllocBufferConfigInfo(TInt aCaptureMode, TInt aNumBuffers); sl@0: TInt ReAllocBufferConfigInfo(TInt aNumBuffers); sl@0: TInt GetSensorCaps(TAny* a1); sl@0: TInt GetFrameSizeCaps(TAny* a1, TAny* a2); sl@0: TInt GetDynamicAttribute(TInt aAttribute, TUint& aValue); sl@0: TInt SetDynamicAttribute(TInt aAttribute, TUint aValue); sl@0: inline DCameraScPdd* Pdd(); sl@0: static void RestartDfc(TAny* aChannel); sl@0: static void PowerUpDfc(TAny* aPtr); sl@0: static void PowerDownDfc(TAny* aPtr); sl@0: private: sl@0: /** An array of configurations for each capture mode. */ sl@0: TCaptureModeConfig* iCaptureModeConfig; sl@0: /** The unit number of this channel. */ sl@0: TInt iUnit; sl@0: /** The operating state of the channel. */ sl@0: TState iState; sl@0: /** A pointer to the owning client thread. */ sl@0: DThread* iOwningThread; sl@0: /** The current capture mode of the camera. */ sl@0: TDevCamCaptureMode iCaptureMode; sl@0: /** The pending request queue. */ sl@0: TCameraScRequestQueue iRequestQueue; sl@0: /** A mutex to protect access to the buffer lists and the pending request list. */ sl@0: NFastMutex iMutex; sl@0: /** The camera driver power handler. */ sl@0: DCameraScPowerHandler* iPowerHandler; sl@0: /** DFC used to re-start the PDD following a data capture error. */ sl@0: TDfc iRestartDfc; sl@0: /** DFC used to handle power down requests from the power manager before a transition into system shutdown/standby. */ sl@0: TDfc iPowerDownDfc; sl@0: /** DFC used to handle power up requests from the power manager following a transition out of system standby. */ sl@0: TDfc iPowerUpDfc; sl@0: sl@0: // Used as a cache for values successfully set by SetDynamicAttribute(). sl@0: TUint iBrightnessValue; sl@0: TUint iContrastValue; sl@0: TUint iColorEffectValue; sl@0: sl@0: friend class DCameraScPowerHandler; sl@0: friend class DBufferManager; sl@0: }; sl@0: sl@0: #include sl@0: sl@0: #endif // __CAMERASC_H__