0
|
1 |
// Copyright (c) 2004-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 the License "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 |
// e32\include\drivers\camerasc.h
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
@internalAll
|
|
21 |
@prototype
|
|
22 |
*/
|
|
23 |
|
|
24 |
#ifndef __CAMERASC_H__
|
|
25 |
#define __CAMERASC_H__
|
|
26 |
|
|
27 |
#include <d32camerasc.h>
|
|
28 |
#include <platform.h>
|
|
29 |
#include <kernel/kpower.h>
|
|
30 |
#include <e32ver.h>
|
|
31 |
|
|
32 |
/** The default number of buffers available to the client. */
|
|
33 |
const TInt KDefaultNumClientBuffers=6;
|
|
34 |
|
|
35 |
/** The maximum number of client capture requests which may be outstanding at any time. */
|
|
36 |
const TInt KMaxCamScRequestsPending=8;
|
|
37 |
|
|
38 |
/**
|
|
39 |
@internalAll
|
|
40 |
@prototype
|
|
41 |
*/
|
|
42 |
struct SBufSpecList
|
|
43 |
{
|
|
44 |
/** The first entry of the buffer offset list. This list holds the offset from the start of the chunk
|
|
45 |
for each buffer. This list is only valid if the flag KScFlagBufOffsetListInUse is set in
|
|
46 |
TSharedChunkBufConfigBase::iFlags. */
|
|
47 |
TInt iBufferOffset;
|
|
48 |
TInt iBufferId;
|
|
49 |
};
|
|
50 |
|
|
51 |
/**
|
|
52 |
@internalAll
|
|
53 |
@prototype
|
|
54 |
*/
|
|
55 |
class TCameraSharedChunkBufConfig : public TSharedChunkBufConfigBase
|
|
56 |
{
|
|
57 |
public:
|
|
58 |
struct SBufSpecList iSpec;
|
|
59 |
};
|
|
60 |
|
|
61 |
// Forward declarations
|
|
62 |
class TImageBuffer;
|
|
63 |
class DCameraScLdd;
|
|
64 |
class DBufferManager;
|
|
65 |
|
|
66 |
/**
|
|
67 |
The physical device driver (PDD) base class for the camera driver.
|
|
68 |
@internalAll
|
|
69 |
@prototype
|
|
70 |
*/
|
|
71 |
class DCameraScPdd : public DBase
|
|
72 |
{
|
|
73 |
public:
|
|
74 |
/**
|
|
75 |
Return the DFC queue to be used by this device.
|
|
76 |
@param aUnit The unit number for which to get the DFC queue.
|
|
77 |
@return The DFC queue to use.
|
|
78 |
*/
|
|
79 |
virtual TDfcQue* DfcQ(TInt aUnit)=0;
|
|
80 |
|
|
81 |
/**
|
|
82 |
Return the capabilities of this camera device.
|
|
83 |
@param aCapsBuf A packaged TCameraCapsV02 object to be filled with the capabilities of the
|
|
84 |
device. This descriptor is in kernel memory and can be accessed directly.
|
|
85 |
@see TCameraCapsV02.
|
|
86 |
*/
|
|
87 |
virtual void Caps(TDes8& aCapsBuf) const=0;
|
|
88 |
|
|
89 |
/**
|
|
90 |
Return data format information for a custom camera data format setting. Only required where support is
|
|
91 |
required for a data format that isn't supported by the LDD. Platforms which don't require support
|
|
92 |
for custom data settings need not implement this method.
|
|
93 |
@param aConfigBuf A packaged TCameraConfigV02 object containing the current camera driver configuration
|
|
94 |
(including an identifier for the custom setting required). This configuration object should be
|
|
95 |
updated by the PDD with the appropriate settings for the data format concerned. This descriptor
|
|
96 |
is in kernel memory and can be accessed directly.
|
|
97 |
@return KErrNone if successful, otherwise one of the other system wide error codes.
|
|
98 |
*/
|
|
99 |
virtual TInt SpecifyCustomConfig(TDes8& aConfigBuf);
|
|
100 |
|
|
101 |
/**
|
|
102 |
Return the shared chunk create information to be used by this device.
|
|
103 |
@param aChunkCreateInfo A chunk create info. object to be to be filled with the settings
|
|
104 |
required for this device.
|
|
105 |
*/
|
|
106 |
virtual void GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo)=0;
|
|
107 |
|
|
108 |
/**
|
|
109 |
Configure or reconfigure the device using the the configuration supplied.
|
|
110 |
@param aConfigBuf A packaged TCameraConfigV02 object which contains the new configuration settings.
|
|
111 |
This descriptor is in kernel memory and can be accessed directly.
|
|
112 |
@return KErrNone if successful, otherwise one of the other system wide error codes.
|
|
113 |
@see TCameraConfigV02.
|
|
114 |
*/
|
|
115 |
virtual TInt SetConfig(const TDesC8& aConfigBuf)=0;
|
|
116 |
|
|
117 |
/**
|
|
118 |
Start the camera - start pixel sourcing.
|
|
119 |
@param aCaptureMode The capture mode to start. @see TDevCamCaptureMode.
|
|
120 |
@param aLinAddr The linear address of the start of the first buffer to use for image capture.
|
|
121 |
@param aPhysAddr The physical address that corresponds to the linear address: aLinAddr.
|
|
122 |
@return KErrNone if successful;
|
|
123 |
otherwise one of the other system wide error codes.
|
|
124 |
*/
|
|
125 |
virtual TInt Start(TDevCamCaptureMode aCaptureMode,TLinAddr aLinAddr,TPhysAddr aPhysAddr)=0;
|
|
126 |
|
|
127 |
/**
|
|
128 |
Sets the address of the buffer into which the next image will be captured.
|
|
129 |
@param aLinAddr The linear address of the start of the buffer to use to capture the image frame.
|
|
130 |
@param aPhysAddr The physical address that corresponds to the linear address: aLinAddr.
|
|
131 |
@return KErrNone if the capture has been initiated successfully;
|
|
132 |
KErrNotReady if the device is unable to accept the request for the moment;
|
|
133 |
otherwise one of the other system-wide error codes.
|
|
134 |
*/
|
|
135 |
virtual TInt CaptureNextImage(TLinAddr aLinAddr,TPhysAddr aPhysAddr)=0;
|
|
136 |
|
|
137 |
/**
|
|
138 |
Stop the camera - stop pixel sourcing.
|
|
139 |
@return KErrNone if successful, otherwise one of the other system wide error codes.
|
|
140 |
*/
|
|
141 |
virtual TInt Stop()=0;
|
|
142 |
|
|
143 |
/**
|
|
144 |
Power down the camera.
|
|
145 |
*/
|
|
146 |
virtual void PowerDown()=0;
|
|
147 |
|
|
148 |
/**
|
|
149 |
Queries the driver for the size of the structure to be passed to RDevCameraSc::Caps().
|
|
150 |
*/
|
|
151 |
virtual TInt CapsSize()=0;
|
|
152 |
|
|
153 |
/**
|
|
154 |
Returns the supported frame sizes that correspond to the desired capture mode and pixel format passed in.
|
|
155 |
@param aCaptureMode The capture mode for which to obtain the information.
|
|
156 |
@param aUidPixelFormat The pixel format for which to obtain the information.
|
|
157 |
@param aFrameSizeCapsBuf An appropriately sized buffer to be filled with the supported frame sizes.
|
|
158 |
@return KErrNone, if successful,
|
|
159 |
KErrArgument, if an invalid capture mode or pixel format is specified, or if aFrameSizeCapsBuf is too small;
|
|
160 |
otherwise one of the other system-wide error codes.
|
|
161 |
@see SDevCamFrameSize
|
|
162 |
*/
|
|
163 |
virtual TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf)=0;
|
|
164 |
|
|
165 |
/**
|
|
166 |
Sets the sensor brightness to the desired setting.
|
|
167 |
|
|
168 |
@param aValue A verified brightness setting.
|
|
169 |
@return KErrNone if successful, KErrNotSupported if not supported.
|
|
170 |
*/
|
|
171 |
virtual TInt SetBrightness(TUint aValue) = 0;
|
|
172 |
|
|
173 |
// SYM_BRANCH: Add support for setting of Dynamic Attributes. Contrast.
|
|
174 |
/**
|
|
175 |
Sets the sensor contrast to the desired setting.
|
|
176 |
|
|
177 |
@param aValue A verified contrast setting.
|
|
178 |
@return KErrNone if successful, KErrNotSupported if not supported.
|
|
179 |
*/
|
|
180 |
virtual TInt SetContrast(TUint aValue) = 0;
|
|
181 |
|
|
182 |
// SYM_BRANCH: Add support for setting of Dynamic Attributes. Colour Effect.
|
|
183 |
/**
|
|
184 |
Sets the sensor color effect to the desired setting.
|
|
185 |
|
|
186 |
@param aValue A verified color effect setting.
|
|
187 |
@return KErrNone if successful, KErrNotSupported if not supported.
|
|
188 |
*/
|
|
189 |
virtual TInt SetColorEffect(TUint aValue) = 0;
|
|
190 |
|
|
191 |
public:
|
|
192 |
DCameraScLdd* iLdd;
|
|
193 |
};
|
|
194 |
|
|
195 |
/**
|
|
196 |
The logical device (factory class) for the camera driver.
|
|
197 |
*/
|
|
198 |
class DCameraScLddFactory : public DLogicalDevice
|
|
199 |
{
|
|
200 |
public:
|
|
201 |
DCameraScLddFactory();
|
|
202 |
virtual TInt Install();
|
|
203 |
virtual void GetCaps(TDes8 &aDes) const;
|
|
204 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
|
205 |
TBool IsUnitOpen(TInt aUnit);
|
|
206 |
TInt SetUnitOpen(TInt aUnit,TBool aIsOpenSetting);
|
|
207 |
private:
|
|
208 |
/** Mask to keep track of which units have a channel open on them. */
|
|
209 |
TUint iUnitsOpenMask;
|
|
210 |
/** A mutex to protect access to the unit info. mask. */
|
|
211 |
NFastMutex iUnitInfoMutex;
|
|
212 |
};
|
|
213 |
|
|
214 |
/**
|
|
215 |
The class representing a single image buffer.
|
|
216 |
*/
|
|
217 |
class TImageBuffer : public SDblQueLink
|
|
218 |
{
|
|
219 |
public:
|
|
220 |
TImageBuffer();
|
|
221 |
~TImageBuffer();
|
|
222 |
TInt Create(DChunk* aChunk,TInt aOffset,TInt aSize,TInt aId,TBool aIsContiguous);
|
|
223 |
void SyncMemoryBeforeDmaRead();
|
|
224 |
void SyncMemoryAfterDmaRead();
|
|
225 |
public:
|
|
226 |
/** The buffer id */
|
|
227 |
TInt iId;
|
|
228 |
/** The chunk used for this buffer */
|
|
229 |
DChunk* iChunk;
|
|
230 |
/** The offset, in bytes, of the start of the buffer within the chunk. */
|
|
231 |
TInt iChunkOffset;
|
|
232 |
/** The size of the buffer in bytes. */
|
|
233 |
TInt iSize;
|
|
234 |
/** The virtual address of buffer. */
|
|
235 |
TLinAddr iLinearAddress;
|
|
236 |
/** The physical address of buffer. KPhysAddrInvalid if the buffer is not physically contiguous. */
|
|
237 |
TPhysAddr iPhysicalAddress;
|
|
238 |
/** A list of physical addresses for buffer pages. 0 if the buffer is physically contiguous. */
|
|
239 |
TPhysAddr* iPhysicalPages;
|
|
240 |
/** This is the result of the transfer into this buffer. */
|
|
241 |
TInt iResult;
|
|
242 |
};
|
|
243 |
|
|
244 |
/**
|
|
245 |
An object encapsulating an image capture request from the client.
|
|
246 |
*/
|
|
247 |
class TCameraScRequest : public SDblQueLink
|
|
248 |
{
|
|
249 |
public:
|
|
250 |
inline TCameraScRequest()
|
|
251 |
{}
|
|
252 |
public:
|
|
253 |
/** The request status associated with the request - used to signal completion of the request and pass back a
|
|
254 |
completion code. */
|
|
255 |
TRequestStatus* iStatus;
|
|
256 |
};
|
|
257 |
|
|
258 |
/**
|
|
259 |
An object encapsulating a queue of image capture requests from the client.
|
|
260 |
*/
|
|
261 |
class TCameraScRequestQueue
|
|
262 |
{
|
|
263 |
public:
|
|
264 |
TCameraScRequestQueue(NFastMutex* aMutexPtr);
|
|
265 |
~TCameraScRequestQueue();
|
|
266 |
TInt Create(DThread* anOwningThread);
|
|
267 |
TInt Add(TRequestStatus* aStatus);
|
|
268 |
TRequestStatus* Remove();
|
|
269 |
void Cancel(TRequestStatus* aStatus);
|
|
270 |
void CancelAll();
|
|
271 |
inline TBool IsEmpty();
|
|
272 |
private:
|
|
273 |
/** The queue of pending capture requests. */
|
|
274 |
SDblQue iPendRequestQ;
|
|
275 |
/** The queue of unused capture requests. */
|
|
276 |
SDblQue iUnusedRequestQ;
|
|
277 |
/** The actual array of request objects. */
|
|
278 |
TCameraScRequest* iRequest[KMaxCamScRequestsPending];
|
|
279 |
NFastMutex* iMutexPtr;
|
|
280 |
DThread* iOwningThread;
|
|
281 |
};
|
|
282 |
|
|
283 |
/**
|
|
284 |
The buffer manager base class.
|
|
285 |
*/
|
|
286 |
class DBufferManager : public DBase
|
|
287 |
{
|
|
288 |
public:
|
|
289 |
DBufferManager(DCameraScLdd* aLdd);
|
|
290 |
~DBufferManager();
|
|
291 |
TInt Create(TInt aNumBuffers,TInt aBufferSize);
|
|
292 |
TInt Create(TCameraSharedChunkBufConfig& aBufConfig,TInt aChunkHandle,DThread* anOwningThread);
|
|
293 |
void GetBufConfig(TCameraSharedChunkBufConfig& aBufConfig);
|
|
294 |
void Reset();
|
|
295 |
void Purge(TImageBuffer* aBuffer);
|
|
296 |
TImageBuffer* GetImageForClient(TBool aRemoveLast);
|
|
297 |
TImageBuffer* SetImageCaptured(TInt aResult);
|
|
298 |
TInt ReleaseImage(TInt aChunkOffset);
|
|
299 |
TImageBuffer* NextAvailableForCapture();
|
|
300 |
TImageBuffer* FindInUseImage(TInt aChunkOffset);
|
|
301 |
protected:
|
|
302 |
TInt CreateBufferLists(TInt aNumBuffers);
|
|
303 |
TInt CommitMemoryForBuffer(TInt aChunkOffset,TInt aSize,TBool& aIsContiguous);
|
|
304 |
protected:
|
|
305 |
/** The owning LDD object. */
|
|
306 |
DCameraScLdd* iLdd;
|
|
307 |
/** The chunk which contains the buffers. */
|
|
308 |
DChunk* iChunk;
|
|
309 |
/** The linear address in kernel process for the start of the chunk. */
|
|
310 |
TLinAddr iChunkBase;
|
|
311 |
/**< MMU mapping attributes that the chunk has actually been mapped with. */
|
|
312 |
TUint32 iChunkMapAttr;
|
|
313 |
/** The number of buffers. */
|
|
314 |
TInt iNumBuffers;
|
|
315 |
/** The actual array of buffer objects. */
|
|
316 |
TImageBuffer* iImageBuffer;
|
|
317 |
/** The buffer currently being filled by image capture. (Not in any list). */
|
|
318 |
TImageBuffer* iCurrentBuffer;
|
|
319 |
/** The next buffer to use for image capture. (Not in any list). */
|
|
320 |
TImageBuffer* iNextBuffer;
|
|
321 |
/** A queue of those buffers which are currently free. */
|
|
322 |
SDblQue iFreeBufferQ;
|
|
323 |
/** A queue of those buffers which currently contain captured images (and which aren't being used by the client). */
|
|
324 |
SDblQue iCompletedBufferQ;
|
|
325 |
/** A queue of those buffers which are currently being used by the client. */
|
|
326 |
SDblQue iInUseBufferQ;
|
|
327 |
private:
|
|
328 |
friend class DCameraScLdd;
|
|
329 |
};
|
|
330 |
|
|
331 |
/**
|
|
332 |
The configuration class that is specific for each capture mode. This allows the driver to maintain different configurations,
|
|
333 |
one for each capture mode, and make switching between capture modes faster.
|
|
334 |
*/
|
|
335 |
class TCaptureModeConfig
|
|
336 |
{
|
|
337 |
private:
|
|
338 |
/** The handle to the chunk that is returned to the user side code. */
|
|
339 |
TInt iChunkHandle;
|
|
340 |
/** The current configuration of the capture mode */
|
|
341 |
TCameraConfigV02 iCamConfig;
|
|
342 |
/** The current configuration of the chunk. */
|
|
343 |
TCameraSharedChunkBufConfig* iBufConfig;
|
|
344 |
/** The size in bytes of the chunk configuration info. structure. */
|
|
345 |
TInt iBufConfigSize;
|
|
346 |
/** The current frame height. */
|
|
347 |
TInt iFrameHeight;
|
|
348 |
/** The current frame width. */
|
|
349 |
TInt iFrameWidth;
|
|
350 |
/** The buffer manager. */
|
|
351 |
DBufferManager* iBufManager;
|
|
352 |
private:
|
|
353 |
friend class DCameraScLdd;
|
|
354 |
};
|
|
355 |
|
|
356 |
/**
|
|
357 |
The camera driver power handler class.
|
|
358 |
*/
|
|
359 |
class DCameraScPowerHandler : public DPowerHandler
|
|
360 |
{
|
|
361 |
public:
|
|
362 |
DCameraScPowerHandler(DCameraScLdd* aChannel);
|
|
363 |
// Inherited from DPowerHandler
|
|
364 |
void PowerUp();
|
|
365 |
void PowerDown(TPowerState aPowerState);
|
|
366 |
private:
|
|
367 |
DCameraScLdd* iChannel;
|
|
368 |
};
|
|
369 |
|
|
370 |
/**
|
|
371 |
The logical channel class for the camera driver.
|
|
372 |
*/
|
|
373 |
class DCameraScLdd : public DLogicalChannel
|
|
374 |
{
|
|
375 |
public:
|
|
376 |
enum TState
|
|
377 |
{
|
|
378 |
/** Channel open - but not configured. */
|
|
379 |
EOpen,
|
|
380 |
/** Channel configured - but inactive. */
|
|
381 |
EConfigured,
|
|
382 |
/** Channel is active - capturing images. */
|
|
383 |
ECapturing
|
|
384 |
};
|
|
385 |
public:
|
|
386 |
DCameraScLdd();
|
|
387 |
virtual ~DCameraScLdd();
|
|
388 |
// Inherited from DLogicalChannel
|
|
389 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
|
390 |
virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
|
|
391 |
virtual void HandleMsg(TMessageBase* aMsg);
|
|
392 |
virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
|
|
393 |
inline DThread* OwningThread();
|
|
394 |
inline TInt CurrentFrameHeight();
|
|
395 |
inline TInt CurrentFrameWidth();
|
|
396 |
void Shutdown();
|
|
397 |
virtual TInt ImageCaptureCallback(TDevCamCaptureMode aCaptureMode,TInt aResult,TLinAddr* aLinAddr,TPhysAddr* aPhysAddr);
|
|
398 |
virtual void PanicClientThread(TInt aReason);
|
|
399 |
private:
|
|
400 |
TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
|
|
401 |
TInt DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2);
|
|
402 |
TInt DoCancel(TUint aMask);
|
|
403 |
TInt SetCaptureMode(TInt aCaptureMode);
|
|
404 |
TInt SetCamConfig(TInt aCaptureMode, const TDesC8* aCamConfigBuf);
|
|
405 |
TInt SetBufConfig(TInt aCaptureMode, const TDesC8* aBufferConfigBuf,TInt aChunkHandle);
|
|
406 |
TInt SetBufConfig(TInt aCaptureMode, TInt aNumBuffers);
|
|
407 |
TInt ChunkClose(TInt aCaptureMode);
|
|
408 |
TInt Start();
|
|
409 |
TInt NotifyNewImage(TRequestStatus* aStatus);
|
|
410 |
TInt ReleaseBuffer(TInt aChunkOffset);
|
|
411 |
TInt DoSetConfig(TInt aCaptureMode, const TDesC8* aCamConfigBuf);
|
|
412 |
TInt ValidateConfig(TInt aCaptureMode, TCameraConfigV02 &aConfig);
|
|
413 |
TInt DoValidateConfig(TCameraCapsV02* aCamCaps, TInt &aCaptureMode, TCameraConfigV02 &aConfig);
|
|
414 |
TInt DoStart();
|
|
415 |
TInt ReAllocBufferConfigInfo(TInt aCaptureMode, TInt aNumBuffers);
|
|
416 |
TInt ReAllocBufferConfigInfo(TInt aNumBuffers);
|
|
417 |
TInt GetSensorCaps(TAny* a1);
|
|
418 |
TInt GetFrameSizeCaps(TAny* a1, TAny* a2);
|
|
419 |
TInt SetDynamicAttribute(TInt aAttribute, TUint aValue);
|
|
420 |
inline DCameraScPdd* Pdd();
|
|
421 |
static void RestartDfc(TAny* aChannel);
|
|
422 |
static void PowerUpDfc(TAny* aPtr);
|
|
423 |
static void PowerDownDfc(TAny* aPtr);
|
|
424 |
private:
|
|
425 |
/** An array of configurations for each capture mode. */
|
|
426 |
TCaptureModeConfig* iCaptureModeConfig;
|
|
427 |
/** The unit number of this channel. */
|
|
428 |
TInt iUnit;
|
|
429 |
/** The operating state of the channel. */
|
|
430 |
TState iState;
|
|
431 |
/** A pointer to the owning client thread. */
|
|
432 |
DThread* iOwningThread;
|
|
433 |
/** The current capture mode of the camera. */
|
|
434 |
TDevCamCaptureMode iCaptureMode;
|
|
435 |
/** The pending request queue. */
|
|
436 |
TCameraScRequestQueue iRequestQueue;
|
|
437 |
/** A mutex to protect access to the buffer lists and the pending request list. */
|
|
438 |
NFastMutex iMutex;
|
|
439 |
/** The camera driver power handler. */
|
|
440 |
DCameraScPowerHandler* iPowerHandler;
|
|
441 |
/** DFC used to re-start the PDD following a data capture error. */
|
|
442 |
TDfc iRestartDfc;
|
|
443 |
/** DFC used to handle power down requests from the power manager before a transition into system shutdown/standby. */
|
|
444 |
TDfc iPowerDownDfc;
|
|
445 |
/** DFC used to handle power up requests from the power manager following a transition out of system standby. */
|
|
446 |
TDfc iPowerUpDfc;
|
|
447 |
friend class DCameraScPowerHandler;
|
|
448 |
friend class DBufferManager;
|
|
449 |
};
|
|
450 |
|
|
451 |
#include <drivers/camerasc.inl>
|
|
452 |
|
|
453 |
#endif // __CAMERASC_H__
|