bsptemplate/asspandvariant/template_variant/camerasc/camerasc_sensor.cpp
changeset 31 56f325a607ea
parent 0 a41df078684a
child 258 880ff05ad710
equal deleted inserted replaced
15:4122176ea935 31:56f325a607ea
    24 #include "camerasc_plat.h"
    24 #include "camerasc_plat.h"
    25 #include <kernel/cache.h>
    25 #include <kernel/cache.h>
    26 
    26 
    27 // XXX - Temporary structure containing a logo to be displayed.  Remove this when
    27 // XXX - Temporary structure containing a logo to be displayed.  Remove this when
    28 //       changing this template into a "real" camera driver
    28 //       changing this template into a "real" camera driver
    29 #include "logo.cpp"
    29 #include "logoyuv2.cpp"
       
    30 
       
    31 
       
    32 #define RGBtoBGR565(red, green, blue) (((blue & 0xf8) << 8) | ((green & 0xfc) << 3) | ((red & 0xf8) >> 3));
       
    33 
       
    34 #define YUVtoYUV565(luma, blueC, redC) (((luma & 0xf8) << 8) | ((blueC & 0xfc) << 3) | ((redC & 0xf8) >> 3));
    30 
    35 
    31 // Frame sizes and their associated frame rates supported by the Template sensor.  This selection was
    36 // Frame sizes and their associated frame rates supported by the Template sensor.  This selection was
    32 // obtained by observation of typical formats supported by phones already on the market;  It is arbitrary
    37 // obtained by observation of typical formats supported by phones already on the market;  It is arbitrary
    33 // and can be easily added to if desired
    38 // and can be easily added to if desired
    34 static const SDevCamFrameSize FrameSizes[] =
    39 static const SDevCamFrameSize FrameSizes[] =
    35 	{
    40 	{
    36 		{ 320, 240, 1, 30 }			// QVGA - 0.075 MP
    41 		{ 320, 240, 1, 30 }	,		// QVGA - 0.075 MP
    37 		// XXX: Although not used in this template driver, the following are suggested standard frame sizes
    42 		// XXX: Although not used in this template driver, the following are suggested standard frame sizes
    38 		// that should be implemented in your camera driver, as well as 320 x 240 above.  Remember to change
    43 		// that should be implemented in your camera driver, as well as 320 x 240 above.  Remember to change
    39 		// KNumFrameSizes below if you change the number of sizes defined in here!
    44 		// KNumFrameSizes below if you change the number of sizes defined in here!
    40 		//{ 640, 480, 1, 30 },		// VGA - 0.3 MP
    45 		{ 640, 480, 1, 30 },		// VGA - 0.3 MP
    41 		//{ 800, 600, 1, 30 },		// SVGA - 0.5 MP
    46 		{ 800, 600, 1, 30 },		// SVGA - 0.5 MP
    42 		//{ 1024, 768, 1, 30 },		// XGA - 0.8 MP
    47 		{ 1024, 768, 1, 30 },		// XGA - 0.8 MP
    43 		//{ 2048, 1536, 1, 30 },	// QXGA - 3 MP
    48 		{ 2048, 1536, 1, 15 },	// QXGA - 3 MP
    44 		//{ 2560, 1600, 1, 30 }		// WQXGA - 4.1 MP
    49 		//{ 2560, 1600, 1, 30 }		// WQXGA - 4.1 MP
    45 	};
    50 	};
    46 
    51 
    47 // This constant must be updated if the number of frame sizes listed above changes
    52 // This constant must be updated if the number of frame sizes listed above changes
    48 static const TInt KNumFrameSizes = 1;
    53 static const TInt KNumFrameSizes = sizeof(FrameSizes) / sizeof(SDevCamFrameSize);
    49 
    54 
    50 // Pixel formats supported by the three different capture modes.  These are mapped onto the appropriate
    55 // Pixel formats supported by the three different capture modes.  These are mapped onto the appropriate
    51 // array of supported frame rates by the FrameSizeCaps() function
    56 // array of supported frame rates by the FrameSizeCaps() function
    52 static const SDevCamPixelFormat PixelFormats[] =
    57 static const SDevCamPixelFormat PixelFormats[] =
    53 	{
    58 	{
    54 		// Image pixel formats
    59 		// Image pixel formats
    55 		{ EUidPixelFormatRGB_565, KNumFrameSizes, 2 },
    60 		{ EUidPixelFormatYUV_422Interleaved, KNumFrameSizes, 2 },
       
    61 		
    56 		// Video pixel formats
    62 		// Video pixel formats
    57 		{ EUidPixelFormatRGB_565, KNumFrameSizes, 2 },
    63 		{ EUidPixelFormatYUV_422Interleaved, KNumFrameSizes, 2 },
       
    64 
    58 		// View finder pixel formats
    65 		// View finder pixel formats
    59 		{ EUidPixelFormatRGB_565, KNumFrameSizes, 2 }
    66 		{ EUidPixelFormatYUV_422Interleaved, KNumFrameSizes, 2 }
       
    67 
    60 	};
    68 	};
    61 
    69 
    62 // These constants must be updated if the number of pixel formats listed above changes
    70 // These constants must be updated if the number of pixel formats listed above changes
    63 static const TInt KNumImagePixelFormats = 1;
    71 static const TInt KNumImagePixelFormats = 1;
    64 static const TInt KNumVideoPixelFormats = 1;
    72 static const TInt KNumVideoPixelFormats = 1;
    65 static const TInt KNumViewFinderPixelFormats = 1;
    73 static const TInt KNumViewFinderPixelFormats = 1;
       
    74 
       
    75 // Alternate logo images after this many frames
       
    76 static const TInt KAlternateLogoFrameInterval = 5;
    66 
    77 
    67 static void ImageTimerCallback(TAny* aSensorIf)
    78 static void ImageTimerCallback(TAny* aSensorIf)
    68 	{
    79 	{
    69 	DTemplateSensorIf* sensor = (DTemplateSensorIf*) aSensorIf;
    80 	DTemplateSensorIf* sensor = (DTemplateSensorIf*) aSensorIf;
    70 
    81 
    83 */
    94 */
    84 TInt DSensorIf::SetConfig(const TCameraConfigV02& aConfig)
    95 TInt DSensorIf::SetConfig(const TCameraConfigV02& aConfig)
    85 	{
    96 	{
    86 	// Manual settings for flash mode, focus, white balance etc. are not supported by the sensor,
    97 	// Manual settings for flash mode, focus, white balance etc. are not supported by the sensor,
    87 	// so check for these and return KErrNotSupported if they have been requested
    98 	// so check for these and return KErrNotSupported if they have been requested
    88 	if ((aConfig.iFlashMode != ECamFlashNone) || (aConfig.iExposureMode != ECamExposureAuto) ||
    99 	if ((aConfig.iFlashMode != ECamFlashNone) ||
    89 		(aConfig.iWhiteBalanceMode != ECamWBAuto) || (aConfig.iZoom != 0))
   100 		(aConfig.iExposureMode != ECamExposureAuto) ||
       
   101 		(aConfig.iZoom != 0) /*||
       
   102         (aConfig.iWhiteBalanceMode != ECamWBAuto) ||
       
   103 		(aConfig.iContrast != ECamContrastAuto) ||
       
   104 		(aConfig.iBrightness != ECamBrightnessAuto)*/)
    90 		{
   105 		{
    91 		// XXX: Remove this once support is addded for these modes
   106 		// XXX: Remove this once support is addded for these modes
    92 		return KErrNotSupported;
   107 		return KErrNotSupported;
    93 		}
   108 		}
    94 
   109 
   109 DTemplateSensorIf::DTemplateSensorIf(MSensorObserver& aObserver, TDfcQue* aDFCQueue)
   124 DTemplateSensorIf::DTemplateSensorIf(MSensorObserver& aObserver, TDfcQue* aDFCQueue)
   110 	: iDFCQueue(aDFCQueue)
   125 	: iDFCQueue(aDFCQueue)
   111 	{
   126 	{
   112 	iObserver = &aObserver;
   127 	iObserver = &aObserver;
   113 	iXDirection = iYDirection = 1;
   128 	iXDirection = iYDirection = 1;
       
   129 	
       
   130 	iCounter = 0;
       
   131 	iFlipSwitch = EFalse;
   114 	}
   132 	}
   115 
   133 
   116 /**
   134 /**
   117 Second stage constructor for the Template sensor class.
   135 Second stage constructor for the Template sensor class.
   118 
   136 
   197 @param aBuffer	Pointer to the buffer to be filled.
   215 @param aBuffer	Pointer to the buffer to be filled.
   198 */
   216 */
   199 void DTemplateSensorIf::FillBuffer(TLinAddr aBuffer)
   217 void DTemplateSensorIf::FillBuffer(TLinAddr aBuffer)
   200 	{
   218 	{
   201 	const TUint8* LogoData = Logo.iPixelData;
   219 	const TUint8* LogoData = Logo.iPixelData;
       
   220 	const TUint8* LogoData2 = Logo.iPixelData2;
   202 	TInt index = 0;
   221 	TInt index = 0;
   203 	TInt numPixels = (iConfig.iFrameSize.iWidth * iConfig.iFrameSize.iHeight);
   222 	TInt numPixels = (iConfig.iFrameSize.iWidth * iConfig.iFrameSize.iHeight);
   204 	TUint r, g, b;
   223 	TUint yC, uC, vC;
   205 	TUint16* buffer = (TUint16*) aBuffer;
   224 	TUint16* buffer = (TUint16*) aBuffer;
   206 
   225 
       
   226     // Alternate between the two logos for cheesy animation effect
       
   227     if( ++iCounter == KAlternateLogoFrameInterval )
       
   228          {
       
   229          iFlipSwitch ^= 1;
       
   230          iCounter = 0;
       
   231          }
       
   232 	
       
   233 	
   207 	// Set the "photo" background to be all white
   234 	// Set the "photo" background to be all white
   208 	memset(buffer, 0xff, (numPixels * 2));
   235 	memset(buffer, 0xff, (numPixels * 2));
   209 
   236 
   210 	// Point to the correct location in the buffer at which to render the logo
   237 	// Point to the correct location in the buffer at which to render the logo
   211 	buffer += ((iY * iConfig.iFrameSize.iWidth) + iX);
   238 	buffer += ((iY * iConfig.iFrameSize.iWidth) + iX);
   215 		{
   242 		{
   216 		for (TUint x = 0; x < Logo.iWidth; ++x)
   243 		for (TUint x = 0; x < Logo.iWidth; ++x)
   217 			{
   244 			{
   218 			// The logo is in 24 bit BGR format so read each pixel and convert it to 16 bit BGR565
   245 			// The logo is in 24 bit BGR format so read each pixel and convert it to 16 bit BGR565
   219 			// before writing it into the "photo" buffer
   246 			// before writing it into the "photo" buffer
   220 			b = LogoData[index];
   247 			if( iFlipSwitch )
   221 			g = LogoData[index + 1];
   248 			    {
   222 			r = LogoData[index + 2];
   249                 yC = LogoData[index];
   223 			*buffer++ = (((b & 0xf8) << 8) | ((g & 0xfc) << 3) | ((r & 0xf8) >> 3));
   250                 uC = LogoData[index + 1];
   224 
   251                 vC = LogoData[index + 2];
       
   252 			    }
       
   253 			else
       
   254                 {
       
   255                 yC = LogoData2[index];
       
   256                 uC = LogoData2[index + 1];
       
   257                 vC = LogoData2[index + 2];
       
   258                 }
       
   259 
       
   260 			*buffer++ = YUVtoYUV565(yC, uC, vC);
   225 			// Point to the next source pixel
   261 			// Point to the next source pixel
   226 			index += 3;
   262 			index += 3;
   227 			}
   263 			}
   228 
   264 
   229 			// Point to the start of the next line in the buffer, taking into account that the logo
   265 			// Point to the start of the next line in the buffer, taking into account that the logo
   278 @param aFrameSizeCapsBuf	A reference to a descriptor that contains a buffer into which to place
   314 @param aFrameSizeCapsBuf	A reference to a descriptor that contains a buffer into which to place
   279 							the frame size structures.  It is up to the LDD to ensure that this is
   315 							the frame size structures.  It is up to the LDD to ensure that this is
   280 							large enough to hold all of the frame sizes.
   316 							large enough to hold all of the frame sizes.
   281 @return Always KErrNone.
   317 @return Always KErrNone.
   282 */
   318 */
   283 TInt DTemplateSensorIf::FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf)
   319 TInt DTemplateSensorIf::FrameSizeCaps(TDevCamCaptureMode /*aCaptureMode*/, TUidPixelFormat /*aUidPixelFormat*/, TDes8& aFrameSizeCapsBuf)
   284 	{
   320 	{
   285 	TPtrC8 sourceFrameSizes((const TUint8*) FrameSizes, sizeof(FrameSizes));
   321 	TPtrC8 sourceFrameSizes((const TUint8*) FrameSizes, sizeof(FrameSizes));
   286 
   322 
   287 	// Ensure the buffer passed in from the LDD is large enough and copy the requested frame sizes
   323 	// Ensure the buffer passed in from the LDD is large enough and copy the requested frame sizes
   288 	__ASSERT_DEBUG((aFrameSizeCapsBuf.Size() >= sourceFrameSizes.Size()), Kern::Fault("camerasc", ECapsBufferTooSmall));
   324 	if (aFrameSizeCapsBuf.Size() < sourceFrameSizes.Size())
       
   325 		{
       
   326 		Kern::Printf("*** ECapsBufferTooSmall: %d vs %d",
       
   327 				aFrameSizeCapsBuf.Size(),
       
   328 				sourceFrameSizes.Size());
       
   329 		Kern::Fault("camerasc", ECapsBufferTooSmall);
       
   330 		}
       
   331 	
       
   332 	//__ASSERT_DEBUG((aFrameSizeCapsBuf.Size() >= sourceFrameSizes.Size()), Kern::Fault("camerasc", ECapsBufferTooSmall));
   289 	aFrameSizeCapsBuf = sourceFrameSizes;
   333 	aFrameSizeCapsBuf = sourceFrameSizes;
   290 
   334 
   291 	return KErrNone;
   335 	return KErrNone;
   292 	}
   336 	}
   293 
   337 
   309 	if (capsBuffer)
   353 	if (capsBuffer)
   310 		{
   354 		{
   311 		aCameraCaps = (TCameraCapsV02*) capsBuffer;
   355 		aCameraCaps = (TCameraCapsV02*) capsBuffer;
   312 
   356 
   313 		// No special modes are supported at the moment
   357 		// No special modes are supported at the moment
   314 		aCameraCaps->iFlashModes = 0;
   358 		aCameraCaps->iFlashModes = ECamFlashNone;
   315 		aCameraCaps->iExposureModes = 0;
   359 		aCameraCaps->iExposureModes = ECamExposureAuto; // or None?
   316 		aCameraCaps->iWhiteBalanceModes = 0;
   360 		// do we still need whitebalance mode filed?
       
   361 		aCameraCaps->iWhiteBalanceModes = ECamWBAuto | ECamWBDaylight | ECamWBCloudy | ECamWBTungsten | ECamWBFluorescent | ECamWBFlash | ECamWBSnow | ECamWBBeach;
   317 		aCameraCaps->iMinZoom = 0;
   362 		aCameraCaps->iMinZoom = 0;
   318 		aCameraCaps->iMaxZoom = 0;
   363 		aCameraCaps->iMaxZoom = 0;
   319 		aCameraCaps->iCapsMisc = 0;
   364 		aCameraCaps->iCapsMisc = KCamMiscContrast | KCamMiscBrightness | KCamMiscColorEffect;
   320 
   365 
   321 		// There isn't really such thing as inwards or outwards orientation on an SDP, but we'll pretend it's
   366 		// There isn't really such thing as inwards or outwards orientation on an SDP, but we'll pretend it's
   322 		// an outwards facing camera
   367 		// an outwards facing camera
   323 		aCameraCaps->iOrientation = ECamOrientationOutwards;
   368 		aCameraCaps->iOrientation = ECamOrientationOutwards;
   324 
   369 
   325 		// Initialise the number of different pixel formats supported
   370 		// Initialise the number of different pixel formats supported
   326 		aCameraCaps->iNumImagePixelFormats = KNumImagePixelFormats;
   371 		aCameraCaps->iNumImagePixelFormats = KNumImagePixelFormats;
   327 		aCameraCaps->iNumVideoPixelFormats = KNumVideoPixelFormats;
   372 		aCameraCaps->iNumVideoPixelFormats = KNumVideoPixelFormats;
   328 		aCameraCaps->iNumViewFinderPixelFormats = KNumViewFinderPixelFormats;
   373 		aCameraCaps->iNumViewFinderPixelFormats = KNumViewFinderPixelFormats;
       
   374 
       
   375 		for (TInt i = 0; i < ECamAttributeMax; i++)
       
   376 		    {
       
   377 		    if (ECamAttributeColorEffect == (TDevCamDynamicAttribute)(i))
       
   378 		        {
       
   379 		        // WhiteBalance
       
   380 		        // In case of white balance, we shouldn't use MIN and MAX values as some of them in between MIN and MAX can be missed out.
       
   381 		        // As this is fake driver, There doesn't seem to be any major issue though.
       
   382 		        aCameraCaps->iDynamicRange[i].iMin = ECamWBAuto;
       
   383 		        aCameraCaps->iDynamicRange[i].iMax = ECamWBBeach;
       
   384 		        aCameraCaps->iDynamicRange[i].iDefault = ECamWBAuto;
       
   385 		        }
       
   386 		    else
       
   387 		        {    
       
   388 		        // TBC :: Contrast, Brightness
       
   389 		        aCameraCaps->iDynamicRange[i].iMin = 0;
       
   390 		        aCameraCaps->iDynamicRange[i].iMax = 6;
       
   391 		        aCameraCaps->iDynamicRange[i].iDefault = 3;
       
   392 		        }
       
   393 		    }
   329 
   394 
   330 		// Setup some descriptors pointing to the pixel format array and the array passed in by the LDD
   395 		// Setup some descriptors pointing to the pixel format array and the array passed in by the LDD
   331 		// (located at the end of the TCameraCapsV02 structure) and copy the pixel format array
   396 		// (located at the end of the TCameraCapsV02 structure) and copy the pixel format array
   332 		TPtrC8 sourcePixelFormats((const TUint8*) PixelFormats, sizeof(PixelFormats));
   397 		TPtrC8 sourcePixelFormats((const TUint8*) PixelFormats, sizeof(PixelFormats));
   333 		TPtr8 destPixelFormats((capsBuffer + sizeof(TCameraCapsV02)), sizeof(PixelFormats), sizeof(PixelFormats));
   398 		TPtr8 destPixelFormats((capsBuffer + sizeof(TCameraCapsV02)), sizeof(PixelFormats), sizeof(PixelFormats));
   381 					This points to the same memory as aLinAddr.
   446 					This points to the same memory as aLinAddr.
   382 @return KErrNone if successful.
   447 @return KErrNone if successful.
   383 		KErrNotReady if there are no free requests to capture the image.
   448 		KErrNotReady if there are no free requests to capture the image.
   384 		Otherwise one of the other system wide error codes.
   449 		Otherwise one of the other system wide error codes.
   385 */
   450 */
   386 TInt DTemplateSensorIf::CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr)
   451 TInt DTemplateSensorIf::CaptureNextImage(TLinAddr aLinAddr, TPhysAddr /*aPhysAddr*/)
   387 	{
   452 	{
   388 	TInt r = KErrNone;
   453 	TInt r = KErrNone;
   389 
   454 
   390 	// Only start capturing the next image if there are any pending request slots available
   455 	// Only start capturing the next image if there are any pending request slots available
   391 	if (iPendingRequests < KTotalCameraRequests)
   456 	if (iPendingRequests < KTotalCameraRequests)
   434 @return KErrNone if successful
   499 @return KErrNone if successful
   435 		KErrInUse if capture is already under way.
   500 		KErrInUse if capture is already under way.
   436 		KErrNotSupported if the frame size and/or frame rate are out of range.
   501 		KErrNotSupported if the frame size and/or frame rate are out of range.
   437 		Otherwise one of the other system wide error codes.
   502 		Otherwise one of the other system wide error codes.
   438 */
   503 */
   439 TInt DTemplateSensorIf::Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr)
   504 TInt DTemplateSensorIf::Start(TDevCamCaptureMode /*aCaptureMode*/, TLinAddr aLinAddr, TPhysAddr aPhysAddr)
   440 	{
   505 	{
   441 	__KTRACE_CAM(Kern::Printf("> DTemplateSensorIf::Start()"));
   506 	__KTRACE_CAM(Kern::Printf("> DTemplateSensorIf::Start()"));
   442 
   507 
   443 	TInt r = KErrNone;
   508 	TInt r = KErrNone;
   444 
   509